glob.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. // Approach:
  2. //
  3. // 1. Get the minimatch set
  4. // 2. For each pattern in the set, PROCESS(pattern, false)
  5. // 3. Store matches per-set, then uniq them
  6. //
  7. // PROCESS(pattern, inGlobStar)
  8. // Get the first [n] items from pattern that are all strings
  9. // Join these together. This is PREFIX.
  10. // If there is no more remaining, then stat(PREFIX) and
  11. // add to matches if it succeeds. END.
  12. //
  13. // If inGlobStar and PREFIX is symlink and points to dir
  14. // set ENTRIES = []
  15. // else readdir(PREFIX) as ENTRIES
  16. // If fail, END
  17. //
  18. // with ENTRIES
  19. // If pattern[n] is GLOBSTAR
  20. // // handle the case where the globstar match is empty
  21. // // by pruning it out, and testing the resulting pattern
  22. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  23. // // handle other cases.
  24. // for ENTRY in ENTRIES (not dotfiles)
  25. // // attach globstar + tail onto the entry
  26. // // Mark that this entry is a globstar match
  27. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  28. //
  29. // else // not globstar
  30. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  31. // Test ENTRY against pattern[n]
  32. // If fails, continue
  33. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  34. //
  35. // Caveat:
  36. // Cache all stats and readdirs results to minimize syscall. Since all
  37. // we ever care about is existence and directory-ness, we can just keep
  38. // `true` for files, and [children,...] for directories, or `false` for
  39. // things that don't exist.
  40. module.exports = glob
  41. var fs = require('fs')
  42. var rp = require('fs.realpath')
  43. var minimatch = require('minimatch')
  44. var Minimatch = minimatch.Minimatch
  45. var inherits = require('inherits')
  46. var EE = require('events').EventEmitter
  47. var path = require('path')
  48. var assert = require('assert')
  49. var isAbsolute = require('path-is-absolute')
  50. var globSync = require('./sync.js')
  51. var common = require('./common.js')
  52. var setopts = common.setopts
  53. var ownProp = common.ownProp
  54. var inflight = require('inflight')
  55. var util = require('util')
  56. var childrenIgnored = common.childrenIgnored
  57. var isIgnored = common.isIgnored
  58. var once = require('once')
  59. function glob (pattern, options, cb) {
  60. if (typeof options === 'function') cb = options, options = {}
  61. if (!options) options = {}
  62. if (options.sync) {
  63. if (cb)
  64. throw new TypeError('callback provided to sync glob')
  65. return globSync(pattern, options)
  66. }
  67. return new Glob(pattern, options, cb)
  68. }
  69. glob.sync = globSync
  70. var GlobSync = glob.GlobSync = globSync.GlobSync
  71. // old api surface
  72. glob.glob = glob
  73. function extend (origin, add) {
  74. if (add === null || typeof add !== 'object') {
  75. return origin
  76. }
  77. var keys = Object.keys(add)
  78. var i = keys.length
  79. while (i--) {
  80. origin[keys[i]] = add[keys[i]]
  81. }
  82. return origin
  83. }
  84. glob.hasMagic = function (pattern, options_) {
  85. var options = extend({}, options_)
  86. options.noprocess = true
  87. var g = new Glob(pattern, options)
  88. var set = g.minimatch.set
  89. if (!pattern)
  90. return false
  91. if (set.length > 1)
  92. return true
  93. for (var j = 0; j < set[0].length; j++) {
  94. if (typeof set[0][j] !== 'string')
  95. return true
  96. }
  97. return false
  98. }
  99. glob.Glob = Glob
  100. inherits(Glob, EE)
  101. function Glob (pattern, options, cb) {
  102. if (typeof options === 'function') {
  103. cb = options
  104. options = null
  105. }
  106. if (options && options.sync) {
  107. if (cb)
  108. throw new TypeError('callback provided to sync glob')
  109. return new GlobSync(pattern, options)
  110. }
  111. if (!(this instanceof Glob))
  112. return new Glob(pattern, options, cb)
  113. setopts(this, pattern, options)
  114. this._didRealPath = false
  115. // process each pattern in the minimatch set
  116. var n = this.minimatch.set.length
  117. // The matches are stored as {<filename>: true,...} so that
  118. // duplicates are automagically pruned.
  119. // Later, we do an Object.keys() on these.
  120. // Keep them as a list so we can fill in when nonull is set.
  121. this.matches = new Array(n)
  122. if (typeof cb === 'function') {
  123. cb = once(cb)
  124. this.on('error', cb)
  125. this.on('end', function (matches) {
  126. cb(null, matches)
  127. })
  128. }
  129. var self = this
  130. this._processing = 0
  131. this._emitQueue = []
  132. this._processQueue = []
  133. this.paused = false
  134. if (this.noprocess)
  135. return this
  136. if (n === 0)
  137. return done()
  138. var sync = true
  139. for (var i = 0; i < n; i ++) {
  140. this._process(this.minimatch.set[i], i, false, done)
  141. }
  142. sync = false
  143. function done () {
  144. --self._processing
  145. if (self._processing <= 0) {
  146. if (sync) {
  147. process.nextTick(function () {
  148. self._finish()
  149. })
  150. } else {
  151. self._finish()
  152. }
  153. }
  154. }
  155. }
  156. Glob.prototype._finish = function () {
  157. assert(this instanceof Glob)
  158. if (this.aborted)
  159. return
  160. if (this.realpath && !this._didRealpath)
  161. return this._realpath()
  162. common.finish(this)
  163. this.emit('end', this.found)
  164. }
  165. Glob.prototype._realpath = function () {
  166. if (this._didRealpath)
  167. return
  168. this._didRealpath = true
  169. var n = this.matches.length
  170. if (n === 0)
  171. return this._finish()
  172. var self = this
  173. for (var i = 0; i < this.matches.length; i++)
  174. this._realpathSet(i, next)
  175. function next () {
  176. if (--n === 0)
  177. self._finish()
  178. }
  179. }
  180. Glob.prototype._realpathSet = function (index, cb) {
  181. var matchset = this.matches[index]
  182. if (!matchset)
  183. return cb()
  184. var found = Object.keys(matchset)
  185. var self = this
  186. var n = found.length
  187. if (n === 0)
  188. return cb()
  189. var set = this.matches[index] = Object.create(null)
  190. found.forEach(function (p, i) {
  191. // If there's a problem with the stat, then it means that
  192. // one or more of the links in the realpath couldn't be
  193. // resolved. just return the abs value in that case.
  194. p = self._makeAbs(p)
  195. rp.realpath(p, self.realpathCache, function (er, real) {
  196. if (!er)
  197. set[real] = true
  198. else if (er.syscall === 'stat')
  199. set[p] = true
  200. else
  201. self.emit('error', er) // srsly wtf right here
  202. if (--n === 0) {
  203. self.matches[index] = set
  204. cb()
  205. }
  206. })
  207. })
  208. }
  209. Glob.prototype._mark = function (p) {
  210. return common.mark(this, p)
  211. }
  212. Glob.prototype._makeAbs = function (f) {
  213. return common.makeAbs(this, f)
  214. }
  215. Glob.prototype.abort = function () {
  216. this.aborted = true
  217. this.emit('abort')
  218. }
  219. Glob.prototype.pause = function () {
  220. if (!this.paused) {
  221. this.paused = true
  222. this.emit('pause')
  223. }
  224. }
  225. Glob.prototype.resume = function () {
  226. if (this.paused) {
  227. this.emit('resume')
  228. this.paused = false
  229. if (this._emitQueue.length) {
  230. var eq = this._emitQueue.slice(0)
  231. this._emitQueue.length = 0
  232. for (var i = 0; i < eq.length; i ++) {
  233. var e = eq[i]
  234. this._emitMatch(e[0], e[1])
  235. }
  236. }
  237. if (this._processQueue.length) {
  238. var pq = this._processQueue.slice(0)
  239. this._processQueue.length = 0
  240. for (var i = 0; i < pq.length; i ++) {
  241. var p = pq[i]
  242. this._processing--
  243. this._process(p[0], p[1], p[2], p[3])
  244. }
  245. }
  246. }
  247. }
  248. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  249. assert(this instanceof Glob)
  250. assert(typeof cb === 'function')
  251. if (this.aborted)
  252. return
  253. this._processing++
  254. if (this.paused) {
  255. this._processQueue.push([pattern, index, inGlobStar, cb])
  256. return
  257. }
  258. //console.error('PROCESS %d', this._processing, pattern)
  259. // Get the first [n] parts of pattern that are all strings.
  260. var n = 0
  261. while (typeof pattern[n] === 'string') {
  262. n ++
  263. }
  264. // now n is the index of the first one that is *not* a string.
  265. // see if there's anything else
  266. var prefix
  267. switch (n) {
  268. // if not, then this is rather simple
  269. case pattern.length:
  270. this._processSimple(pattern.join('/'), index, cb)
  271. return
  272. case 0:
  273. // pattern *starts* with some non-trivial item.
  274. // going to readdir(cwd), but not include the prefix in matches.
  275. prefix = null
  276. break
  277. default:
  278. // pattern has some string bits in the front.
  279. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  280. // or 'relative' like '../baz'
  281. prefix = pattern.slice(0, n).join('/')
  282. break
  283. }
  284. var remain = pattern.slice(n)
  285. // get the list of entries.
  286. var read
  287. if (prefix === null)
  288. read = '.'
  289. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  290. if (!prefix || !isAbsolute(prefix))
  291. prefix = '/' + prefix
  292. read = prefix
  293. } else
  294. read = prefix
  295. var abs = this._makeAbs(read)
  296. //if ignored, skip _processing
  297. if (childrenIgnored(this, read))
  298. return cb()
  299. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  300. if (isGlobStar)
  301. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
  302. else
  303. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
  304. }
  305. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  306. var self = this
  307. this._readdir(abs, inGlobStar, function (er, entries) {
  308. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  309. })
  310. }
  311. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  312. // if the abs isn't a dir, then nothing can match!
  313. if (!entries)
  314. return cb()
  315. // It will only match dot entries if it starts with a dot, or if
  316. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  317. var pn = remain[0]
  318. var negate = !!this.minimatch.negate
  319. var rawGlob = pn._glob
  320. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  321. var matchedEntries = []
  322. for (var i = 0; i < entries.length; i++) {
  323. var e = entries[i]
  324. if (e.charAt(0) !== '.' || dotOk) {
  325. var m
  326. if (negate && !prefix) {
  327. m = !e.match(pn)
  328. } else {
  329. m = e.match(pn)
  330. }
  331. if (m)
  332. matchedEntries.push(e)
  333. }
  334. }
  335. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  336. var len = matchedEntries.length
  337. // If there are no matched entries, then nothing matches.
  338. if (len === 0)
  339. return cb()
  340. // if this is the last remaining pattern bit, then no need for
  341. // an additional stat *unless* the user has specified mark or
  342. // stat explicitly. We know they exist, since readdir returned
  343. // them.
  344. if (remain.length === 1 && !this.mark && !this.stat) {
  345. if (!this.matches[index])
  346. this.matches[index] = Object.create(null)
  347. for (var i = 0; i < len; i ++) {
  348. var e = matchedEntries[i]
  349. if (prefix) {
  350. if (prefix !== '/')
  351. e = prefix + '/' + e
  352. else
  353. e = prefix + e
  354. }
  355. if (e.charAt(0) === '/' && !this.nomount) {
  356. e = path.join(this.root, e)
  357. }
  358. this._emitMatch(index, e)
  359. }
  360. // This was the last one, and no stats were needed
  361. return cb()
  362. }
  363. // now test all matched entries as stand-ins for that part
  364. // of the pattern.
  365. remain.shift()
  366. for (var i = 0; i < len; i ++) {
  367. var e = matchedEntries[i]
  368. var newPattern
  369. if (prefix) {
  370. if (prefix !== '/')
  371. e = prefix + '/' + e
  372. else
  373. e = prefix + e
  374. }
  375. this._process([e].concat(remain), index, inGlobStar, cb)
  376. }
  377. cb()
  378. }
  379. Glob.prototype._emitMatch = function (index, e) {
  380. if (this.aborted)
  381. return
  382. if (isIgnored(this, e))
  383. return
  384. if (this.paused) {
  385. this._emitQueue.push([index, e])
  386. return
  387. }
  388. var abs = isAbsolute(e) ? e : this._makeAbs(e)
  389. if (this.mark)
  390. e = this._mark(e)
  391. if (this.absolute)
  392. e = abs
  393. if (this.matches[index][e])
  394. return
  395. if (this.nodir) {
  396. var c = this.cache[abs]
  397. if (c === 'DIR' || Array.isArray(c))
  398. return
  399. }
  400. this.matches[index][e] = true
  401. var st = this.statCache[abs]
  402. if (st)
  403. this.emit('stat', e, st)
  404. this.emit('match', e)
  405. }
  406. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  407. if (this.aborted)
  408. return
  409. // follow all symlinked directories forever
  410. // just proceed as if this is a non-globstar situation
  411. if (this.follow)
  412. return this._readdir(abs, false, cb)
  413. var lstatkey = 'lstat\0' + abs
  414. var self = this
  415. var lstatcb = inflight(lstatkey, lstatcb_)
  416. if (lstatcb)
  417. fs.lstat(abs, lstatcb)
  418. function lstatcb_ (er, lstat) {
  419. if (er && er.code === 'ENOENT')
  420. return cb()
  421. var isSym = lstat && lstat.isSymbolicLink()
  422. self.symlinks[abs] = isSym
  423. // If it's not a symlink or a dir, then it's definitely a regular file.
  424. // don't bother doing a readdir in that case.
  425. if (!isSym && lstat && !lstat.isDirectory()) {
  426. self.cache[abs] = 'FILE'
  427. cb()
  428. } else
  429. self._readdir(abs, false, cb)
  430. }
  431. }
  432. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  433. if (this.aborted)
  434. return
  435. cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
  436. if (!cb)
  437. return
  438. //console.error('RD %j %j', +inGlobStar, abs)
  439. if (inGlobStar && !ownProp(this.symlinks, abs))
  440. return this._readdirInGlobStar(abs, cb)
  441. if (ownProp(this.cache, abs)) {
  442. var c = this.cache[abs]
  443. if (!c || c === 'FILE')
  444. return cb()
  445. if (Array.isArray(c))
  446. return cb(null, c)
  447. }
  448. var self = this
  449. fs.readdir(abs, readdirCb(this, abs, cb))
  450. }
  451. function readdirCb (self, abs, cb) {
  452. return function (er, entries) {
  453. if (er)
  454. self._readdirError(abs, er, cb)
  455. else
  456. self._readdirEntries(abs, entries, cb)
  457. }
  458. }
  459. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  460. if (this.aborted)
  461. return
  462. // if we haven't asked to stat everything, then just
  463. // assume that everything in there exists, so we can avoid
  464. // having to stat it a second time.
  465. if (!this.mark && !this.stat) {
  466. for (var i = 0; i < entries.length; i ++) {
  467. var e = entries[i]
  468. if (abs === '/')
  469. e = abs + e
  470. else
  471. e = abs + '/' + e
  472. this.cache[e] = true
  473. }
  474. }
  475. this.cache[abs] = entries
  476. return cb(null, entries)
  477. }
  478. Glob.prototype._readdirError = function (f, er, cb) {
  479. if (this.aborted)
  480. return
  481. // handle errors, and cache the information
  482. switch (er.code) {
  483. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  484. case 'ENOTDIR': // totally normal. means it *does* exist.
  485. var abs = this._makeAbs(f)
  486. this.cache[abs] = 'FILE'
  487. if (abs === this.cwdAbs) {
  488. var error = new Error(er.code + ' invalid cwd ' + this.cwd)
  489. error.path = this.cwd
  490. error.code = er.code
  491. this.emit('error', error)
  492. this.abort()
  493. }
  494. break
  495. case 'ENOENT': // not terribly unusual
  496. case 'ELOOP':
  497. case 'ENAMETOOLONG':
  498. case 'UNKNOWN':
  499. this.cache[this._makeAbs(f)] = false
  500. break
  501. default: // some unusual error. Treat as failure.
  502. this.cache[this._makeAbs(f)] = false
  503. if (this.strict) {
  504. this.emit('error', er)
  505. // If the error is handled, then we abort
  506. // if not, we threw out of here
  507. this.abort()
  508. }
  509. if (!this.silent)
  510. console.error('glob error', er)
  511. break
  512. }
  513. return cb()
  514. }
  515. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  516. var self = this
  517. this._readdir(abs, inGlobStar, function (er, entries) {
  518. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  519. })
  520. }
  521. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  522. //console.error('pgs2', prefix, remain[0], entries)
  523. // no entries means not a dir, so it can never have matches
  524. // foo.txt/** doesn't match foo.txt
  525. if (!entries)
  526. return cb()
  527. // test without the globstar, and with every child both below
  528. // and replacing the globstar.
  529. var remainWithoutGlobStar = remain.slice(1)
  530. var gspref = prefix ? [ prefix ] : []
  531. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  532. // the noGlobStar pattern exits the inGlobStar state
  533. this._process(noGlobStar, index, false, cb)
  534. var isSym = this.symlinks[abs]
  535. var len = entries.length
  536. // If it's a symlink, and we're in a globstar, then stop
  537. if (isSym && inGlobStar)
  538. return cb()
  539. for (var i = 0; i < len; i++) {
  540. var e = entries[i]
  541. if (e.charAt(0) === '.' && !this.dot)
  542. continue
  543. // these two cases enter the inGlobStar state
  544. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  545. this._process(instead, index, true, cb)
  546. var below = gspref.concat(entries[i], remain)
  547. this._process(below, index, true, cb)
  548. }
  549. cb()
  550. }
  551. Glob.prototype._processSimple = function (prefix, index, cb) {
  552. // XXX review this. Shouldn't it be doing the mounting etc
  553. // before doing stat? kinda weird?
  554. var self = this
  555. this._stat(prefix, function (er, exists) {
  556. self._processSimple2(prefix, index, er, exists, cb)
  557. })
  558. }
  559. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  560. //console.error('ps2', prefix, exists)
  561. if (!this.matches[index])
  562. this.matches[index] = Object.create(null)
  563. // If it doesn't exist, then just mark the lack of results
  564. if (!exists)
  565. return cb()
  566. if (prefix && isAbsolute(prefix) && !this.nomount) {
  567. var trail = /[\/\\]$/.test(prefix)
  568. if (prefix.charAt(0) === '/') {
  569. prefix = path.join(this.root, prefix)
  570. } else {
  571. prefix = path.resolve(this.root, prefix)
  572. if (trail)
  573. prefix += '/'
  574. }
  575. }
  576. if (process.platform === 'win32')
  577. prefix = prefix.replace(/\\/g, '/')
  578. // Mark this as a match
  579. this._emitMatch(index, prefix)
  580. cb()
  581. }
  582. // Returns either 'DIR', 'FILE', or false
  583. Glob.prototype._stat = function (f, cb) {
  584. var abs = this._makeAbs(f)
  585. var needDir = f.slice(-1) === '/'
  586. if (f.length > this.maxLength)
  587. return cb()
  588. if (!this.stat && ownProp(this.cache, abs)) {
  589. var c = this.cache[abs]
  590. if (Array.isArray(c))
  591. c = 'DIR'
  592. // It exists, but maybe not how we need it
  593. if (!needDir || c === 'DIR')
  594. return cb(null, c)
  595. if (needDir && c === 'FILE')
  596. return cb()
  597. // otherwise we have to stat, because maybe c=true
  598. // if we know it exists, but not what it is.
  599. }
  600. var exists
  601. var stat = this.statCache[abs]
  602. if (stat !== undefined) {
  603. if (stat === false)
  604. return cb(null, stat)
  605. else {
  606. var type = stat.isDirectory() ? 'DIR' : 'FILE'
  607. if (needDir && type === 'FILE')
  608. return cb()
  609. else
  610. return cb(null, type, stat)
  611. }
  612. }
  613. var self = this
  614. var statcb = inflight('stat\0' + abs, lstatcb_)
  615. if (statcb)
  616. fs.lstat(abs, statcb)
  617. function lstatcb_ (er, lstat) {
  618. if (lstat && lstat.isSymbolicLink()) {
  619. // If it's a symlink, then treat it as the target, unless
  620. // the target does not exist, then treat it as a file.
  621. return fs.stat(abs, function (er, stat) {
  622. if (er)
  623. self._stat2(f, abs, null, lstat, cb)
  624. else
  625. self._stat2(f, abs, er, stat, cb)
  626. })
  627. } else {
  628. self._stat2(f, abs, er, lstat, cb)
  629. }
  630. }
  631. }
  632. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  633. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  634. this.statCache[abs] = false
  635. return cb()
  636. }
  637. var needDir = f.slice(-1) === '/'
  638. this.statCache[abs] = stat
  639. if (abs.slice(-1) === '/' && stat && !stat.isDirectory())
  640. return cb(null, false, stat)
  641. var c = true
  642. if (stat)
  643. c = stat.isDirectory() ? 'DIR' : 'FILE'
  644. this.cache[abs] = this.cache[abs] || c
  645. if (needDir && c === 'FILE')
  646. return cb()
  647. return cb(null, c, stat)
  648. }