From eaf970cc1fd1d128dcdf8a014fa8a0608f681b01 Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Sun, 28 Apr 2024 16:24:35 +0800 Subject: [PATCH] re-write logic Signed-off-by: Kevin Cui --- lib/filesystem.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/filesystem.js b/lib/filesystem.js index 106035a..d921c50 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -99,13 +99,13 @@ class Filesystem { } insertLink (p) { - const realSrcPath = fs.realpathSync(this.src) - const target = path.join(path.dirname(p), fs.readlinkSync(p)) - const relativePath = path.relative(realSrcPath, fs.realpathSync(target)) - if (relativePath.startsWith('..')) { - throw new Error(`${p}: file "${relativePath}" links out of the package`) + const symlink = fs.readlinkSync(p) + // /var => /private/var + const parentPath = fs.realpathSync(path.dirname(p)) + const link = path.relative(fs.realpathSync(this.src), path.join(parentPath, symlink)) + if (link.startsWith('..')) { + throw new Error(`${p}: file "${link}" links out of the package`) } - const link = path.relative(this.src, target) const node = this.searchNodeFromPath(p) node.link = link return link