mirror of
https://github.com/electron/node-gyp.git
synced 2025-09-16 05:53:41 +02:00
update fstream to v0.1.18
This commit is contained in:
parent
a07f082717
commit
aa8bc9d7cf
9 changed files with 275 additions and 124 deletions
111
node_modules/fstream/lib/dir-reader.js
generated
vendored
111
node_modules/fstream/lib/dir-reader.js
generated
vendored
|
@ -11,6 +11,7 @@ var fs = require("graceful-fs")
|
|||
, mkdir = require("mkdirp")
|
||||
, path = require("path")
|
||||
, Reader = require("./reader.js")
|
||||
, assert = require("assert").ok
|
||||
|
||||
inherits(DirReader, Reader)
|
||||
|
||||
|
@ -24,25 +25,42 @@ function DirReader (props) {
|
|||
throw new Error("Non-directory type "+ props.type)
|
||||
}
|
||||
|
||||
me._entries = null
|
||||
me.entries = null
|
||||
me._index = -1
|
||||
me._paused = false
|
||||
me._length = -1
|
||||
|
||||
if (props.sort) {
|
||||
this.sort = props.sort
|
||||
}
|
||||
|
||||
Reader.call(this, props)
|
||||
}
|
||||
|
||||
DirReader.prototype._getEntries = function () {
|
||||
var me = this
|
||||
|
||||
// race condition. might pause() before calling _getEntries,
|
||||
// and then resume, and try to get them a second time.
|
||||
if (me._gotEntries) return
|
||||
me._gotEntries = true
|
||||
|
||||
fs.readdir(me._path, function (er, entries) {
|
||||
if (er) return me.error(er)
|
||||
me._entries = entries
|
||||
me._length = entries.length
|
||||
// console.error("DR %s sort =", me.path, me.props.sort)
|
||||
if (typeof me.props.sort === "function") {
|
||||
me._entries.sort(me.props.sort)
|
||||
|
||||
me.entries = entries
|
||||
|
||||
me.emit("entries", entries)
|
||||
if (me._paused) me.once("resume", processEntries)
|
||||
else processEntries()
|
||||
|
||||
function processEntries () {
|
||||
me._length = me.entries.length
|
||||
if (typeof me.sort === "function") {
|
||||
me.entries = me.entries.sort(me.sort.bind(me))
|
||||
}
|
||||
me._read()
|
||||
}
|
||||
me._read()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -50,7 +68,7 @@ DirReader.prototype._getEntries = function () {
|
|||
DirReader.prototype._read = function () {
|
||||
var me = this
|
||||
|
||||
if (!me._entries) return me._getEntries()
|
||||
if (!me.entries) return me._getEntries()
|
||||
|
||||
if (me._paused || me._currentEntry || me._aborted) {
|
||||
// console.error("DR paused=%j, current=%j, aborted=%j", me._paused, !!me._currentEntry, me._aborted)
|
||||
|
@ -58,7 +76,7 @@ DirReader.prototype._read = function () {
|
|||
}
|
||||
|
||||
me._index ++
|
||||
if (me._index >= me._length) {
|
||||
if (me._index >= me.entries.length) {
|
||||
if (!me._ended) {
|
||||
me._ended = true
|
||||
me.emit("end")
|
||||
|
@ -70,20 +88,26 @@ DirReader.prototype._read = function () {
|
|||
// ok, handle this one, then.
|
||||
|
||||
// save creating a proxy, by stat'ing the thing now.
|
||||
var p = path.resolve(me._path, me._entries[me._index])
|
||||
var p = path.resolve(me._path, me.entries[me._index])
|
||||
assert(p !== me._path)
|
||||
assert(me.entries[me._index])
|
||||
|
||||
// set this to prevent trying to _read() again in the stat time.
|
||||
me._currentEntry = p
|
||||
fs[ me.props.follow ? "stat" : "lstat" ](p, function (er, stat) {
|
||||
if (er) return me.error(er)
|
||||
|
||||
var entry = Reader({ path: p
|
||||
, depth: me.depth + 1
|
||||
, root: me.root || me._proxy || me
|
||||
, parent: me._proxy || me
|
||||
, follow: me.follow
|
||||
, filter: me.filter
|
||||
, sort: me.props.sort
|
||||
}, stat)
|
||||
var who = me._proxy || me
|
||||
|
||||
stat.path = p
|
||||
stat.basename = path.basename(p)
|
||||
stat.dirname = path.dirname(p)
|
||||
var childProps = me.getChildProps.call(who, stat)
|
||||
childProps.path = p
|
||||
childProps.basename = path.basename(p)
|
||||
childProps.dirname = path.dirname(p)
|
||||
|
||||
var entry = Reader(childProps, stat)
|
||||
|
||||
// console.error("DR Entry", p, stat.size)
|
||||
|
||||
|
@ -94,17 +118,25 @@ DirReader.prototype._read = function () {
|
|||
// This nomenclature is not completely final.
|
||||
|
||||
entry.on("pause", function (who) {
|
||||
if (!me._paused) {
|
||||
if (!me._paused && !entry._disowned) {
|
||||
me.pause(who)
|
||||
}
|
||||
})
|
||||
|
||||
entry.on("resume", function (who) {
|
||||
if (me._paused) {
|
||||
if (me._paused && !entry._disowned) {
|
||||
me.resume(who)
|
||||
}
|
||||
})
|
||||
|
||||
entry.on("stat", function (props) {
|
||||
me.emit("_entryStat", entry, props)
|
||||
if (entry._aborted) return
|
||||
if (entry._paused) entry.once("resume", function () {
|
||||
me.emit("entryStat", entry, props)
|
||||
})
|
||||
})
|
||||
|
||||
entry.on("ready", function EMITCHILD () {
|
||||
// console.error("DR emit child", entry._path)
|
||||
if (me._paused) {
|
||||
|
@ -122,23 +154,25 @@ DirReader.prototype._read = function () {
|
|||
if (entry.type === "Socket") {
|
||||
me.emit("socket", entry)
|
||||
} else {
|
||||
me.emit("entry", entry)
|
||||
me.emit("child", entry)
|
||||
me.emitEntry(entry)
|
||||
}
|
||||
})
|
||||
|
||||
var ended = false
|
||||
entry.on("close", onend)
|
||||
entry.on("disown", onend)
|
||||
function onend () {
|
||||
if (ended) return
|
||||
ended = true
|
||||
me.emit("childEnd", entry)
|
||||
me.emit("entryEnd", entry)
|
||||
me._currentEntry = null
|
||||
me._read()
|
||||
if (!me._paused) {
|
||||
me._read()
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Make this work in node.
|
||||
// XXX Remove this. Works in node as of 0.6.2 or so.
|
||||
// Long filenames should not break stuff.
|
||||
entry.on("error", function (er) {
|
||||
if (entry._swallowErrors) {
|
||||
|
@ -160,6 +194,26 @@ DirReader.prototype._read = function () {
|
|||
})
|
||||
}
|
||||
|
||||
DirReader.prototype.disown = function (entry) {
|
||||
entry.emit("beforeDisown")
|
||||
entry._disowned = true
|
||||
entry.parent = entry.root = null
|
||||
if (entry === this._currentEntry) {
|
||||
this._currentEntry = null
|
||||
}
|
||||
entry.emit("disown")
|
||||
}
|
||||
|
||||
DirReader.prototype.getChildProps = function (stat) {
|
||||
return { depth: this.depth + 1
|
||||
, root: this.root || this
|
||||
, parent: this
|
||||
, follow: this.follow
|
||||
, filter: this.filter
|
||||
, sort: this.props.sort
|
||||
}
|
||||
}
|
||||
|
||||
DirReader.prototype.pause = function (who) {
|
||||
var me = this
|
||||
if (me._paused) return
|
||||
|
@ -185,8 +239,11 @@ DirReader.prototype.resume = function (who) {
|
|||
}
|
||||
|
||||
if (me._currentEntry) {
|
||||
if (me._currentEntry.resume) {
|
||||
me._currentEntry.resume(who)
|
||||
}
|
||||
if (me._currentEntry.resume) me._currentEntry.resume(who)
|
||||
} else me._read()
|
||||
}
|
||||
|
||||
DirReader.prototype.emitEntry = function (entry) {
|
||||
this.emit("entry", entry)
|
||||
this.emit("child", entry)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue