Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use stat instead of lstat when checking CWD
This allows CWD to be a symbolic link. Fixes #204

Fix #204
Fix #214

Edit: added test, added support for sync case -- @isaacs
  • Loading branch information
stkb authored and isaacs committed Jun 2, 2019
1 parent 49058cb commit 77522f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/mkdir.js
Expand Up @@ -69,7 +69,7 @@ const mkdir = module.exports = (dir, opt, cb) => {
return done()

if (dir === cwd)
return fs.lstat(dir, (er, st) => {
return fs.stat(dir, (er, st) => {
if (er || !st.isDirectory())
er = new CwdError(dir, er && er.code || 'ENOTDIR')
done(er)
Expand Down Expand Up @@ -154,7 +154,7 @@ const mkdirSync = module.exports.sync = (dir, opt) => {
let ok = false
let code = 'ENOTDIR'
try {
ok = fs.lstatSync(dir).isDirectory()
ok = fs.statSync(dir).isDirectory()
} catch (er) {
code = er.code
} finally {
Expand Down
11 changes: 7 additions & 4 deletions test/unpack.js
Expand Up @@ -79,9 +79,12 @@ t.test('basic file unpack tests', t => {
t.test(tarfile, t => {
const tf = path.resolve(tars, tarfile)
const dir = path.resolve(basedir, tarfile)
const linkdir = path.resolve(basedir, tarfile + '.link')
t.beforeEach(cb => {
rimraf.sync(dir)
rimraf.sync(linkdir)
mkdirp.sync(dir)
fs.symlinkSync(dir, linkdir)
cb()
})

Expand All @@ -99,12 +102,12 @@ t.test('basic file unpack tests', t => {
t.test('async unpack', t => {
t.plan(2)
t.test('strict', t => {
const unpack = new Unpack({ cwd: dir, strict: true })
const unpack = new Unpack({ cwd: linkdir, strict: true })
fs.createReadStream(tf).pipe(unpack)
eos(unpack, _ => check(t))
})
t.test('loose', t => {
const unpack = new Unpack({ cwd: dir })
const unpack = new Unpack({ cwd: linkdir })
fs.createReadStream(tf).pipe(unpack)
eos(unpack, _ => check(t))
})
Expand All @@ -113,12 +116,12 @@ t.test('basic file unpack tests', t => {
t.test('sync unpack', t => {
t.plan(2)
t.test('strict', t => {
const unpack = new UnpackSync({ cwd: dir })
const unpack = new UnpackSync({ cwd: linkdir })
unpack.end(fs.readFileSync(tf))
check(t)
})
t.test('loose', t => {
const unpack = new UnpackSync({ cwd: dir })
const unpack = new UnpackSync({ cwd: linkdir })
unpack.end(fs.readFileSync(tf))
check(t)
})
Expand Down

0 comments on commit 77522f0

Please sign in to comment.