Skip to content

Commit

Permalink
(fix #248) follow directory links in getNode
Browse files Browse the repository at this point in the history
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 committed Nov 5, 2024
1 parent 84fe52c commit a05f9b6
Showing 1 changed file with 5 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

0 comments on commit a05f9b6

Please sign in to comment.