Skip to content

Commit

Permalink
re-write logic
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cui <bh@bugs.cc>
  • Loading branch information
BlackHole1 committed Apr 28, 2024
1 parent ad7d2d5 commit eaf970c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaf970c

Please sign in to comment.