Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable getNode to follow directory links (fixes #248) #318

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
@@ -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`);
4 changes: 4 additions & 0 deletions test/api-spec.js
Original file line number Diff line number Diff line change
@@ -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.