update fstream to v0.1.18

This commit is contained in:
Nathan Rajlich 2012-06-06 14:31:56 -07:00
parent a07f082717
commit aa8bc9d7cf
9 changed files with 275 additions and 124 deletions

229
node_modules/fstream/lib/writer.js generated vendored
View file

@ -123,12 +123,13 @@ Writer.prototype._stat = function (current) {
var me = this
, props = me.props
, stat = props.follow ? "stat" : "lstat"
, who = me._proxy || me
if (current) statCb(null, current)
else fs[stat](me._path, statCb)
function statCb (er, current) {
if (me.filter && !me.filter.call(me._proxy || me, current)) {
if (me.filter && !me.filter.call(who, who, current)) {
me._aborted = true
me.emit("end")
me.emit("close")
@ -165,13 +166,83 @@ function create (me) {
// XXX Need to clobber non-dirs that are in the way,
// unless { clobber: false } in the props.
mkdir(path.dirname(me._path), Writer.dirmode, function (er) {
mkdir(path.dirname(me._path), Writer.dirmode, function (er, made) {
// console.error("W created", path.dirname(me._path), er)
if (er) return me.error(er)
me._create()
// later on, we have to set the mode and owner for these
me._madeDir = made
return me._create()
})
}
function endChmod (me, want, current, path, cb) {
var wantMode = want.mode
, chmod = want.follow || me.type !== "SymbolicLink"
? "chmod" : "lchmod"
if (!fs[chmod]) return cb()
if (typeof wantMode !== "number") return cb()
var curMode = current.mode & 0777
wantMode = wantMode & 0777
if (wantMode === curMode) return cb()
fs[chmod](path, wantMode, cb)
}
function endChown (me, want, current, path, cb) {
// Don't even try it unless root. Too easy to EPERM.
if (process.platform === "win32") return cb()
if (!process.getuid || !process.getuid() === 0) return cb()
if (typeof want.uid !== "number" &&
typeof want.gid !== "number" ) return cb()
if (current.uid === want.uid &&
current.gid === want.gid) return cb()
var chown = (me.props.follow || me.type !== "SymbolicLink")
? "chown" : "lchown"
if (!fs[chown]) return cb()
if (typeof want.uid !== "number") want.uid = current.uid
if (typeof want.gid !== "number") want.gid = current.gid
fs[chown](path, want.uid, want.gid, cb)
}
function endUtimes (me, want, current, path, cb) {
if (!fs.utimes || process.platform === "win32") return cb()
var utimes = (want.follow || me.type !== "SymbolicLink")
? "utimes" : "lutimes"
if (utimes === "lutimes" && !fs[utimes]) {
utimes = "utimes"
}
if (!fs[utimes]) return cb()
var curA = current.atime
, curM = current.mtime
, meA = want.atime
, meM = want.mtime
if (meA === undefined) meA = curA
if (meM === undefined) meM = curM
if (!isDate(meA)) meA = new Date(meA)
if (!isDate(meM)) meA = new Date(meM)
if (meA.getTime() === curA.getTime() &&
meM.getTime() === curM.getTime()) return cb()
fs[utimes](path, meA, meM, cb)
}
// XXX This function is beastly. Break it up!
Writer.prototype._finish = function () {
var me = this
@ -219,88 +290,82 @@ Writer.prototype._finish = function () {
return
function setProps (current) {
// console.error(" W setprops", me._path)
// mode
var wantMode = me.props.mode
, chmod = me.props.follow || me.type !== "SymbolicLink"
? "chmod" : "lchmod"
if (fs[chmod] && typeof wantMode === "number") {
wantMode = wantMode & 0777
todo ++
// console.error(" W chmod", wantMode.toString(8), me.basename, "\r")
fs[chmod](me._path, wantMode, next(chmod))
}
// uid, gid
// Don't even try it unless root. Too easy to EPERM.
if (process.platform !== "win32" &&
process.getuid && process.getuid() === 0 &&
( typeof me.props.uid === "number" ||
typeof me.props.gid === "number" )) {
var chown = (me.props.follow || me.type !== "SymbolicLink")
? "chown" : "lchown"
if (fs[chown]) {
if (typeof me.props.uid !== "number") me.props.uid = current.uid
if (typeof me.props.gid !== "number") me.props.gid = current.gid
if (me.props.uid !== current.uid || me.props.gid !== current.gid) {
todo ++
// console.error(" W chown", me.props.uid, me.props.gid, me.basename)
fs[chown](me._path, me.props.uid, me.props.gid, next("chown"))
}
}
}
// atime, mtime.
if (fs.utimes && process.platform !== "win32") {
var utimes = (me.props.follow || me.type !== "SymbolicLink")
? "utimes" : "lutimes"
if (utimes === "lutimes" && !fs[utimes]) {
utimes = "utimes"
}
var curA = current.atime
, curM = current.mtime
, meA = me.props.atime
, meM = me.props.mtime
if (meA === undefined) meA = curA
if (meM === undefined) meM = curM
if (!isDate(meA)) meA = new Date(meA)
if (!isDate(meM)) meA = new Date(meM)
if (meA.getTime() !== curA.getTime() ||
meM.getTime() !== curM.getTime()) {
todo ++
// console.error(" W utimes", meA, meM, me.basename)
fs[utimes](me._path, meA, meM, next("utimes"))
}
}
// finally, handle the case if there was nothing to do.
if (todo === 0) {
// console.error(" W nothing to do", me.basename)
next("nothing to do")()
}
endChmod(me, me.props, current, me._path, next("chmod"))
endChown(me, me.props, current, me._path, next("chown"))
endUtimes(me, me.props, current, me._path, next("chown"))
}
function next (what) { return function (er) {
// console.error(" W Finish", what, todo)
if (errState) return
if (er) {
er.fstream_finish_call = what
return me.error(errState = er)
}
if (--todo > 0) return
if (done) return
done = true
function next (what) {
todo ++
return function (er) {
// console.error(" W Finish", what, todo)
if (errState) return
if (er) {
er.fstream_finish_call = what
return me.error(errState = er)
}
if (--todo > 0) return
if (done) return
done = true
// all the props have been set, so we're completely done.
me.emit("end")
me.emit("close")
}}
// we may still need to set the mode/etc. on some parent dirs
// that were created previously. delay end/close until then.
if (!me._madeDir) return end()
else endMadeDir(me, me._path, end)
function end (er) {
if (er) {
er.fstream_finish_call = "setupMadeDir"
return me.error(er)
}
// all the props have been set, so we're completely done.
me.emit("end")
me.emit("close")
}
}
}
}
function endMadeDir (me, p, cb) {
var made = me._madeDir
// everything *between* made and path.dirname(me._path)
// needs to be set up. Note that this may just be one dir.
var d = path.dirname(p)
endMadeDir_(me, d, function (er) {
if (er) return cb(er)
if (d === made) {
return cb()
}
endMadeDir(me, d, cb)
})
}
function endMadeDir_ (me, p, cb) {
var dirProps = {}
Object.keys(me.props).forEach(function (k) {
dirProps[k] = me.props[k]
// only make non-readable dirs if explicitly requested.
if (k === "mode" && me.type !== "Directory") {
dirProps[k] = dirProps[k] | 0111
}
})
var todo = 3
, errState = null
fs.stat(p, function (er, current) {
if (er) return cb(errState = er)
endChmod(me, dirProps, current, p, next)
endChown(me, dirProps, current, p, next)
endUtimes(me, dirProps, current, p, next)
})
function next (er) {
if (errState) return
if (er) return cb(errState = er)
if (-- todo === 0) return cb()
}
}
Writer.prototype.pipe = function () {