Skip to content

Commit 647447b

Browse files
authored
check windows tweak (#115)
1 parent e4a7a40 commit 647447b

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

index.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,23 @@ exports.extract = function extract (cwd, opts) {
164164
return next()
165165
}
166166

167-
if (header.type === 'directory') {
168-
stack.push([name, header.mtime])
169-
return mkdirfix(name, {
170-
fs: xfs,
171-
own,
172-
uid: header.uid,
173-
gid: header.gid,
174-
mode: header.mode
175-
}, stat)
176-
}
177-
178-
const dir = path.dirname(name)
167+
const dir = path.join(name, '.') === path.join(cwd, '.') ? cwd : path.dirname(name)
179168

180169
validate(xfs, dir, path.join(cwd, '.'), function (err, valid) {
181170
if (err) return next(err)
182171
if (!valid) return next(new Error(dir + ' is not a valid path'))
183172

173+
if (header.type === 'directory') {
174+
stack.push([name, header.mtime])
175+
return mkdirfix(name, {
176+
fs: xfs,
177+
own,
178+
uid: header.uid,
179+
gid: header.gid,
180+
mode: header.mode
181+
}, stat)
182+
}
183+
184184
mkdirfix(dir, {
185185
fs: xfs,
186186
own,
@@ -228,15 +228,19 @@ exports.extract = function extract (cwd, opts) {
228228
function onlink () {
229229
if (win32) return next() // skip links on win for now before it can be tested
230230
xfs.unlink(name, function () {
231-
const dst = path.join(cwd, path.join('/', header.linkname))
231+
const link = path.join(cwd, path.join('/', header.linkname))
232232

233-
xfs.link(dst, name, function (err) {
234-
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
235-
stream = xfs.createReadStream(dst)
236-
return onfile()
237-
}
233+
fs.realpath(link, function (err, dst) {
234+
if (err || !inCwd(dst)) return next(new Error(name + ' is not a valid hardlink'))
238235

239-
stat(err)
236+
xfs.link(dst, name, function (err) {
237+
if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) {
238+
stream = xfs.createReadStream(dst)
239+
return onfile()
240+
}
241+
242+
stat(err)
243+
})
240244
})
241245
})
242246
}
@@ -317,10 +321,11 @@ exports.extract = function extract (cwd, opts) {
317321

318322
function validate (fs, name, root, cb) {
319323
if (name === root) return cb(null, true)
324+
320325
fs.lstat(name, function (err, st) {
321-
if (err && err.code === 'ENOENT') return validate(fs, path.join(name, '..'), root, cb)
322-
else if (err) return cb(err)
323-
cb(null, st.isDirectory())
326+
if (err && err.code !== 'ENOENT' && err.code !== 'EPERM') return cb(err)
327+
if (err || st.isDirectory()) return validate(fs, path.join(name, '..'), root, cb)
328+
cb(null, false)
324329
})
325330
}
326331

0 commit comments

Comments
 (0)