Skip to content

Commit

Permalink
fix: Enable getNode to follow directory links (fixes #248) (#318)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
AndreasFranek authored Nov 5, 2024
1 parent 546ed91 commit f30b93d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`);
Expand Down
4 changes: 4 additions & 0 deletions test/api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Binary file added test/input/stat-symlink.asar
Binary file not shown.

0 comments on commit f30b93d

Please sign in to comment.