diff options
Diffstat (limited to 'deps/npm/node_modules/glob/sync.js')
-rw-r--r-- | deps/npm/node_modules/glob/sync.js | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/deps/npm/node_modules/glob/sync.js b/deps/npm/node_modules/glob/sync.js index 315fbfb0b4c..f4f5e36d4be 100644 --- a/deps/npm/node_modules/glob/sync.js +++ b/deps/npm/node_modules/glob/sync.js @@ -50,6 +50,24 @@ function GlobSync (pattern, options) { GlobSync.prototype._finish = function () { assert(this instanceof GlobSync) + if (this.realpath) { + var self = this + this.matches.forEach(function (matchset, index) { + var set = self.matches[index] = Object.create(null) + for (var p in matchset) { + try { + p = self._makeAbs(p) + var real = fs.realpathSync(p, this.realpathCache) + set[real] = true + } catch (er) { + if (er.syscall === 'stat') + set[self._makeAbs(p)] = true + else + throw er + } + } + }) + } common.finish(this) } @@ -190,21 +208,31 @@ GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, GlobSync.prototype._emitMatch = function (index, e) { - if (!this.matches[index][e]) { - if (this.nodir) { - var c = this.cache[this._makeAbs(e)] - if (c === 'DIR' || Array.isArray(c)) - return - } + var abs = this._makeAbs(e) + if (this.mark) + e = this._mark(e) + + if (this.matches[index][e]) + return - this.matches[index][e] = true - if (this.stat || this.mark) - this._stat(this._makeAbs(e)) + if (this.nodir) { + var c = this.cache[this._makeAbs(e)] + if (c === 'DIR' || Array.isArray(c)) + return } + + this.matches[index][e] = true + if (this.stat) + this._stat(e) } GlobSync.prototype._readdirInGlobStar = function (abs) { + // follow all symlinked directories forever + // just proceed as if this is a non-globstar situation + if (this.follow) + return this._readdir(abs, false) + var entries var lstat var stat @@ -276,18 +304,18 @@ GlobSync.prototype._readdirError = function (f, er) { // handle errors, and cache the information switch (er.code) { case 'ENOTDIR': // totally normal. means it *does* exist. - this.cache[f] = 'FILE' + this.cache[this._makeAbs(f)] = 'FILE' break case 'ENOENT': // not terribly unusual case 'ELOOP': case 'ENAMETOOLONG': case 'UNKNOWN': - this.cache[f] = false + this.cache[this._makeAbs(f)] = false break default: // some unusual error. Treat as failure. - this.cache[f] = false + this.cache[this._makeAbs(f)] = false if (this.strict) throw er if (!this.silent) console.error('glob error', er) break @@ -365,27 +393,27 @@ GlobSync.prototype._processSimple = function (prefix, index) { // Returns either 'DIR', 'FILE', or false GlobSync.prototype._stat = function (f) { - var abs = f - if (f.charAt(0) === '/') - abs = path.join(this.root, f) - else if (this.changedCwd) - abs = path.resolve(this.cwd, f) - + var abs = this._makeAbs(f) + var needDir = f.slice(-1) === '/' if (f.length > this.maxLength) return false - if (!this.stat && ownProp(this.cache, f)) { - var c = this.cache[f] + if (!this.stat && ownProp(this.cache, abs)) { + var c = this.cache[abs] if (Array.isArray(c)) c = 'DIR' - // It exists, but not how we need it - if (abs.slice(-1) === '/' && c !== 'DIR') + // It exists, but maybe not how we need it + if (!needDir || c === 'DIR') + return c + + if (needDir && c === 'FILE') return false - return c + // otherwise we have to stat, because maybe c=true + // if we know it exists, but not what it is. } var exists @@ -411,11 +439,12 @@ GlobSync.prototype._stat = function (f) { this.statCache[abs] = stat - if (abs.slice(-1) === '/' && !stat.isDirectory()) + var c = stat.isDirectory() ? 'DIR' : 'FILE' + this.cache[abs] = this.cache[abs] || c + + if (needDir && c !== 'DIR') return false - var c = stat.isDirectory() ? 'DIR' : 'FILE' - this.cache[f] = this.cache[f] || c return c } |