From 84fe52c579118bfe68e1b47c2eb96d9814106606 Mon Sep 17 00:00:00 2001 From: Andreas Franek Date: Mon, 12 Aug 2024 10:27:41 +0200 Subject: [PATCH 1/2] Add test failing to stat symlinked file This demonstrates issue #248 --- test/api-spec.js | 4 ++++ test/input/stat-symlink.asar | Bin 0 -> 367 bytes 2 files changed, 4 insertions(+) create mode 100644 test/input/stat-symlink.asar diff --git a/test/api-spec.js b/test/api-spec.js index 892e8142..d88a7bc7 100644 --- a/test/api-spec.js +++ b/test/api-spec.js @@ -168,4 +168,8 @@ describe('api', function () { assert.deepStrictEqual(topLevelFunctions, defaultExportFunctions); }); + it('should stat a symlinked file', async () => { + const stats = asar.statFile('test/input/stat-symlink.asar', 'real.txt', true); + return assert.strictEqual(stats.link, undefined); + }); }); diff --git a/test/input/stat-symlink.asar b/test/input/stat-symlink.asar new file mode 100644 index 0000000000000000000000000000000000000000..2269106ff5d90418103577af042304af38d3de24 GIT binary patch literal 367 zcmbu5QES5>6onn^X}==)99lId(Z0#(SRsS4=3y}Qphg?1OCZT$TiJi#O$nv%6Rvo^ zd(@-12%-80p=YQH>V$oWZp51tR`YaGgVS*}eN8hQ!;ixoDpTBhKRRHT;1q{$a)%*I z-?K-@Ll5ir1Dg9s#qt6itsYy@(s@=8Nx02~CbZ0GRvMi*(#gC5DUE2Xwv6P0m!1*k z3+p|nLQ5fyad47}y*=*FIXIO(BYa^H{q6r3y#K;T@%`s8xbFPs7`h`wR~Yd1Uo3oa Zt}iXvzf06p^0HM`Qoq*8!>-!i{Q+7_X~X~k literal 0 HcmV?d00001 From a05f9b6b7a578432673c8634dfb33c9661d023ec Mon Sep 17 00:00:00 2001 From: Andreas Franek Date: Tue, 24 Sep 2024 17:51:55 +0200 Subject: [PATCH 2/2] (fix #248) follow directory links in getNode When called from stat, getNode should follow directory links to ensure that the correct node is returned. Otherwise, node.files[name] will be undefined, causing a TypeError. --- src/filesystem.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/filesystem.ts b/src/filesystem.ts index c4d68d52..4869f443 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -190,9 +190,12 @@ export class Filesystem { return files; } - getNode(p: string) { + getNode(p: string, followLinks: boolean = true): FilesystemEntry { const node = this.searchNodeFromDirectory(path.dirname(p)); const name = path.basename(p); + if ('link' in node && followLinks) { + return this.getNode(path.join(node.link, name)); + } if (name) { return (node as FilesystemDirectoryEntry).files[name]; } else { @@ -201,7 +204,7 @@ export class Filesystem { } getFile(p: string, followLinks: boolean = true): FilesystemEntry { - const info = this.getNode(p); + const info = this.getNode(p, followLinks); if (!info) { throw new Error(`"${p}" was not found in this archive`);