Skip to content

Commit 8a1675a

Browse files
committed
Assert a symbolic link before dereferencingDirectory
1 parent b8f2795 commit 8a1675a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/host/src/node/path-utils.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,19 @@ describe("dereferenceDirectory", () => {
570570
"file",
571571
);
572572

573+
{
574+
// Verify that outer link is no longer a link
575+
const stat = await fs.promises.lstat(symlinkPath);
576+
assert(stat.isSymbolicLink());
577+
}
578+
573579
await dereferenceDirectory(symlinkPath);
574580

575-
// Verify that outer link is no longer a link
576-
const symlinkStat = await fs.promises.lstat(symlinkPath);
577-
assert(!symlinkStat.isSymbolicLink());
581+
{
582+
// Verify that outer link is no longer a link
583+
const stat = await fs.promises.lstat(symlinkPath);
584+
assert(!stat.isSymbolicLink());
585+
}
578586

579587
// Verify that the internal link is still a link to a readable file
580588
const internalLinkPath = path.join(symlinkPath, "linked-file.txt");

packages/host/src/node/path-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ export function findNodeAddonForBindings(id: string, fromDir: string) {
546546

547547
export async function dereferenceDirectory(dirPath: string) {
548548
const tempPath = dirPath + ".tmp";
549+
const stat = await fs.promises.lstat(dirPath);
550+
assert(stat.isSymbolicLink(), `Expected a symbolic link at: ${dirPath}`);
549551
// Move the existing framework out of the way
550552
await fs.promises.rename(dirPath, tempPath);
551553
// Only dereference the symlink at tempPath (not recursively)

0 commit comments

Comments
 (0)