Skip to content

Commit 77522f0

Browse files
stkbisaacs
authored andcommitted
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
1 parent 49058cb commit 77522f0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/mkdir.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const mkdir = module.exports = (dir, opt, cb) => {
6969
return done()
7070

7171
if (dir === cwd)
72-
return fs.lstat(dir, (er, st) => {
72+
return fs.stat(dir, (er, st) => {
7373
if (er || !st.isDirectory())
7474
er = new CwdError(dir, er && er.code || 'ENOTDIR')
7575
done(er)
@@ -154,7 +154,7 @@ const mkdirSync = module.exports.sync = (dir, opt) => {
154154
let ok = false
155155
let code = 'ENOTDIR'
156156
try {
157-
ok = fs.lstatSync(dir).isDirectory()
157+
ok = fs.statSync(dir).isDirectory()
158158
} catch (er) {
159159
code = er.code
160160
} finally {

test/unpack.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ t.test('basic file unpack tests', t => {
7979
t.test(tarfile, t => {
8080
const tf = path.resolve(tars, tarfile)
8181
const dir = path.resolve(basedir, tarfile)
82+
const linkdir = path.resolve(basedir, tarfile + '.link')
8283
t.beforeEach(cb => {
8384
rimraf.sync(dir)
85+
rimraf.sync(linkdir)
8486
mkdirp.sync(dir)
87+
fs.symlinkSync(dir, linkdir)
8588
cb()
8689
})
8790

@@ -99,12 +102,12 @@ t.test('basic file unpack tests', t => {
99102
t.test('async unpack', t => {
100103
t.plan(2)
101104
t.test('strict', t => {
102-
const unpack = new Unpack({ cwd: dir, strict: true })
105+
const unpack = new Unpack({ cwd: linkdir, strict: true })
103106
fs.createReadStream(tf).pipe(unpack)
104107
eos(unpack, _ => check(t))
105108
})
106109
t.test('loose', t => {
107-
const unpack = new Unpack({ cwd: dir })
110+
const unpack = new Unpack({ cwd: linkdir })
108111
fs.createReadStream(tf).pipe(unpack)
109112
eos(unpack, _ => check(t))
110113
})
@@ -113,12 +116,12 @@ t.test('basic file unpack tests', t => {
113116
t.test('sync unpack', t => {
114117
t.plan(2)
115118
t.test('strict', t => {
116-
const unpack = new UnpackSync({ cwd: dir })
119+
const unpack = new UnpackSync({ cwd: linkdir })
117120
unpack.end(fs.readFileSync(tf))
118121
check(t)
119122
})
120123
t.test('loose', t => {
121-
const unpack = new UnpackSync({ cwd: dir })
124+
const unpack = new UnpackSync({ cwd: linkdir })
122125
unpack.end(fs.readFileSync(tf))
123126
check(t)
124127
})

0 commit comments

Comments
 (0)