Skip to content

Commit 4884466

Browse files
committed
refactor to same pattern as v3
1 parent 3c6eddb commit 4884466

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ exports.extract = function (cwd, opts) {
266266
var srcpath = path.join(cwd, path.join('/', header.linkname))
267267

268268
xfs.realpath(srcpath, function (err, dst) {
269-
if (err || !dst.startsWith(path.resolve(cwd))) return next(new Error(name + ' is not a valid hardlink'))
269+
if (err || !inCwd(dst, cwd)) return next(new Error(name + ' is not a valid hardlink'))
270270

271271
xfs.link(dst, name, function (err) {
272272
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
@@ -349,3 +349,8 @@ function mkdirfix (name, opts, cb) {
349349
}
350350
})
351351
}
352+
353+
function inCwd (dst, cwd) {
354+
cwd = path.resolve(cwd)
355+
return cwd === dst || dst.startsWith(cwd + path.sep)
356+
}

0 commit comments

Comments
 (0)