Skip to content

Commit 266194b

Browse files
committed
hardlink tweak from main
1 parent d97731b commit 266194b

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
@@ -272,13 +272,17 @@ exports.extract = function (cwd, opts) {
272272
xfs.unlink(name, function () {
273273
var srcpath = path.join(cwd, path.join('/', header.linkname))
274274

275-
xfs.link(srcpath, name, function (err) {
276-
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
277-
stream = xfs.createReadStream(srcpath)
278-
return onfile()
279-
}
275+
xfs.realpath(srcpath, function (err, dst) {
276+
if (err || !dst.startsWith(path.resolve(cwd))) return next(new Error(name + ' is not a valid hardlink'))
280277

281-
stat(err)
278+
xfs.link(dst, name, function (err) {
279+
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
280+
stream = xfs.createReadStream(srcpath)
281+
return onfile()
282+
}
283+
284+
stat(err)
285+
})
282286
})
283287
})
284288
}

0 commit comments

Comments
 (0)