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`); 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 00000000..2269106f Binary files /dev/null and b/test/input/stat-symlink.asar differ