Skip to content

Commit f30b93d

Browse files
fix: Enable getNode to follow directory links (fixes #248) (#318)
* Add test failing to stat symlinked file This demonstrates issue #248 * (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.
1 parent 546ed91 commit f30b93d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/filesystem.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,12 @@ export class Filesystem {
190190
return files;
191191
}
192192

193-
getNode(p: string) {
193+
getNode(p: string, followLinks: boolean = true): FilesystemEntry {
194194
const node = this.searchNodeFromDirectory(path.dirname(p));
195195
const name = path.basename(p);
196+
if ('link' in node && followLinks) {
197+
return this.getNode(path.join(node.link, name));
198+
}
196199
if (name) {
197200
return (node as FilesystemDirectoryEntry).files[name];
198201
} else {
@@ -201,7 +204,7 @@ export class Filesystem {
201204
}
202205

203206
getFile(p: string, followLinks: boolean = true): FilesystemEntry {
204-
const info = this.getNode(p);
207+
const info = this.getNode(p, followLinks);
205208

206209
if (!info) {
207210
throw new Error(`"${p}" was not found in this archive`);

test/api-spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,8 @@ describe('api', function () {
168168

169169
assert.deepStrictEqual(topLevelFunctions, defaultExportFunctions);
170170
});
171+
it('should stat a symlinked file', async () => {
172+
const stats = asar.statFile('test/input/stat-symlink.asar', 'real.txt', true);
173+
return assert.strictEqual(stats.link, undefined);
174+
});
171175
});

test/input/stat-symlink.asar

367 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)