Skip to content

Commit

Permalink
Fix race condition when all patterns are ignored
Browse files Browse the repository at this point in the history
Fix #232
  • Loading branch information
isaacs committed Mar 5, 2016
1 parent b63c657 commit 4c79d1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
13 changes: 11 additions & 2 deletions glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,23 @@ function Glob (pattern, options, cb) {
if (n === 0)
return done()

var sync = true
for (var i = 0; i < n; i ++) {
this._process(this.minimatch.set[i], i, false, done)
}
sync = false

function done () {
--self._processing
if (self._processing <= 0)
self._finish()
if (self._processing <= 0) {
if (sync) {
process.nextTick(function () {
self._finish()
})
} else {
self._finish()
}
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,32 @@ cases.forEach(function (c, i) {
})
})
})

test('race condition', function (t) {
process.chdir(__dirname)
var pattern = 'fixtures/*'
;[true, false].forEach(function (dot) {
;['fixtures/**', null].forEach(function (ignore) {
;[false, true].forEach(function (nonull) {
;[false, process.cwd(), '.'].forEach(function (cwd) {
var opt = {
dot: dot,
ignore: ignore,
nonull: nonull,
}
if (cwd)
opt.cwd = cwd
var expect = ignore ? [] : [ 'fixtures/a' ]
t.test(JSON.stringify(opt), function (t) {
t.plan(2)
t.same(glob.sync(pattern, opt), expect)
glob(pattern, opt).on('end', function (res) {
t.same(res, expect)
})
})
})
})
})
})
t.end()
})

0 comments on commit 4c79d1e

Please sign in to comment.