Skip to content

Commit c5e7d96

Browse files
committed
hardlink tweak from main
1 parent ff6510d commit c5e7d96

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,17 @@ exports.extract = function (cwd, opts) {
265265
xfs.unlink(name, function () {
266266
var srcpath = path.join(cwd, path.join('/', header.linkname))
267267

268-
xfs.link(srcpath, name, function (err) {
269-
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
270-
stream = xfs.createReadStream(srcpath)
271-
return onfile()
272-
}
268+
xfs.realpath(srcpath, function (err, dst) {
269+
if (err || !dst.startsWith(path.resolve(cwd))) return next(new Error(name + ' is not a valid hardlink'))
273270

274-
stat(err)
271+
xfs.link(dst, name, function (err) {
272+
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
273+
stream = xfs.createReadStream(srcpath)
274+
return onfile()
275+
}
276+
277+
stat(err)
278+
})
275279
})
276280
})
277281
}

0 commit comments

Comments
 (0)