Browse files

Update vendor/tar for Node v0.10.0+. [closes #218]

  • Loading branch information...
1 parent 88deb9f commit 51fbb0bf15b082ab31871a82ac0be226678b7209 @jdalton jdalton committed Mar 26, 2013
View
0 vendor/tar/vendor/fstream/LICENCE → vendor/tar/LICENCE
File renamed without changes.
View
2 vendor/tar/lib/entry.js
@@ -105,7 +105,7 @@ inherits(Entry, Stream,
this._reading = true
// have any data to emit?
- if (this._index < this._queueLen) {
+ while (this._index < this._queueLen && !this._paused) {
var chunk = this._queue[this._index ++]
this.emit("data", chunk)
}
View
9 vendor/tar/lib/pack.js
@@ -134,19 +134,22 @@ Pack.prototype._process = function () {
var root = path.dirname((entry.root || entry).path)
var wprops = {}
- Object.keys(entry.props).forEach(function (k) {
+ Object.keys(entry.props || {}).forEach(function (k) {
wprops[k] = entry.props[k]
})
if (me._noProprietary) wprops.noProprietary = true
- wprops.path = path.relative(root, entry.path)
+ wprops.path = path.relative(root, entry.path || '')
// actually not a matter of opinion or taste.
if (process.platform === "win32") {
wprops.path = wprops.path.replace(/\\/g, "/")
}
+ if (!wprops.type)
+ wprops.type = 'Directory'
+
switch (wprops.type) {
// sockets not supported
case "Socket":
@@ -156,11 +159,13 @@ Pack.prototype._process = function () {
wprops.path += "/"
wprops.size = 0
break
+
case "Link":
var lp = path.resolve(path.dirname(entry.path), entry.linkpath)
wprops.linkpath = path.relative(root, lp) || "."
wprops.size = 0
break
+
case "SymbolicLink":
var lp = path.resolve(path.dirname(entry.path), entry.linkpath)
wprops.linkpath = path.relative(path.dirname(entry.path), lp) || "."
View
1 vendor/tar/tar.js
@@ -75,6 +75,7 @@ Object.keys(fields).forEach(function (f) {
var types =
{ 0: "File"
, "\0": "OldFile" // like 0
+ , "": "OldFile"
, 1: "Link"
, 2: "SymbolicLink"
, 3: "CharacterDevice"
View
27 vendor/tar/vendor/fstream/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) Isaac Z. Schlueter ("Author")
+All rights reserved.
+
+The BSD License
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
5 vendor/tar/vendor/fstream/lib/file-writer.js
@@ -36,12 +36,15 @@ FileWriter.prototype._create = function () {
me._stream = fs.createWriteStream(me._path, so)
me._stream.on("open", function (fd) {
+ // console.error("FW open", me._buffer, me._path)
me.ready = true
me._buffer.forEach(function (c) {
if (c === EOF) me._stream.end()
else me._stream.write(c)
})
me.emit("ready")
+ // give this a kick just in case it needs it.
+ me.emit("drain")
})
me._stream.on("drain", function () { me.emit("drain") })
@@ -58,6 +61,8 @@ FileWriter.prototype.write = function (c) {
me._bytesWritten += c.length
if (!me.ready) {
+ if (!Buffer.isBuffer(c) && typeof c !== 'string')
+ throw new Error('invalid write data')
me._buffer.push(c)
return false
}
View
4 vendor/tar/vendor/fstream/lib/proxy-writer.js
@@ -71,7 +71,7 @@ ProxyWriter.prototype._addProxy = function (proxy) {
var calls = me._buffer
calls.forEach(function (c) {
// console.error("~~ ~~ proxy buffered call", c[0], c[1])
- proxy[c[0]].call(proxy, c[1])
+ proxy[c[0]].apply(proxy, c[1])
})
me._buffer.length = 0
if (me._needsDrain) me.emit("drain")
@@ -102,7 +102,7 @@ ProxyWriter.prototype.write = function (c) {
ProxyWriter.prototype.end = function (c) {
// console.error("~~ proxy end")
if (!this._proxy) {
- this._buffer.push(["end", c])
+ this._buffer.push(["end", [c]])
return false
}
return this._proxy.end(c)
View
1 vendor/tar/vendor/fstream/lib/reader.js
@@ -256,3 +256,4 @@ Reader.prototype.resume = function (who) {
Reader.prototype._read = function () {
this.error("Cannot read unknown type: "+this.type)
}
+
View
4 vendor/tar/vendor/fstream/lib/writer.js
@@ -290,13 +290,13 @@ Writer.prototype._finish = function () {
return
function setProps (current) {
+ todo += 3
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"))
+ endUtimes(me, me.props, current, me._path, next("utimes"))
}
function next (what) {
- todo ++
return function (er) {
// console.error(" W Finish", what, todo)
if (errState) return
View
10 vendor/tar/vendor/graceful-fs/graceful-fs.js
@@ -1,10 +1,14 @@
// this keeps a queue of opened file descriptors, and will make
// fs operations wait until some have closed before trying to open more.
-var fs = require("fs")
+var fs_ = require("fs")
-// there is such a thing as TOO graceful.
-if (fs.open === gracefulOpen) return
+var fs = module.exports = {}
+
+Object.getOwnPropertyNames(fs_).forEach(function(prop) {
+ var desc = Object.getOwnPropertyDescriptor(fs_, prop)
+ Object.defineProperty(fs, prop, desc)
+})
var queue = []
, constants = require("constants")
View
50 vendor/tar/vendor/mkdirp/README.markdown
@@ -1,34 +1,37 @@
-mkdirp
-======
+# mkdirp
Like `mkdir -p`, but in node.js!
[![build status](https://secure.travis-ci.org/substack/node-mkdirp.png)](http://travis-ci.org/substack/node-mkdirp)
-example
-=======
+# example
-pow.js
-------
- var mkdirp = require('mkdirp');
+## pow.js
+
+```js
+var mkdirp = require('mkdirp');
- mkdirp('/tmp/foo/bar/baz', function (err) {
- if (err) console.error(err)
- else console.log('pow!')
- });
+mkdirp('/tmp/foo/bar/baz', function (err) {
+ if (err) console.error(err)
+ else console.log('pow!')
+});
+```
Output
- pow!
+
+```
+pow!
+```
And now /tmp/foo/bar/baz exists, huzzah!
-methods
-=======
+# methods
+```js
var mkdirp = require('mkdirp');
+```
-mkdirp(dir, mode, cb)
----------------------
+## mkdirp(dir, mode, cb)
Create a new directory and any necessary subdirectories at `dir` with octal
permission string `mode`.
@@ -38,8 +41,7 @@ If `mode` isn't specified, it defaults to `0777 & (~process.umask())`.
`cb(err, made)` fires with the error or the first directory `made`
that had to be created, if any.
-mkdirp.sync(dir, mode)
-----------------------
+## mkdirp.sync(dir, mode)
Synchronously create a new directory and any necessary subdirectories at `dir`
with octal permission string `mode`.
@@ -48,14 +50,14 @@ If `mode` isn't specified, it defaults to `0777 & (~process.umask())`.
Returns the first directory that had to be created, if any.
-install
-=======
+# install
With [npm](http://npmjs.org) do:
- npm install mkdirp
+```
+npm install mkdirp
+```
-license
-=======
+# license
-MIT/X11
+MIT
View
163 vendor/tar/vendor/rimraf/rimraf.js
@@ -11,28 +11,15 @@ try {
fs = require("fs")
}
-var lstat = "lstat"
-if (process.platform === "win32") {
- // not reliable on windows prior to 0.7.9
- var v = process.version.replace(/^v/, '').split(/\.|-/).map(Number)
- if (v[0] === 0 && (v[1] < 7 || v[1] == 7 && v[2] < 9)) {
- lstat = "stat"
- }
-}
-if (!fs[lstat]) lstat = "stat"
-var lstatSync = lstat + "Sync"
-
// for EMFILE handling
var timeout = 0
exports.EMFILE_MAX = 1000
exports.BUSYTRIES_MAX = 3
function rimraf (p, cb) {
-
if (!cb) throw new Error("No callback passed to rimraf()")
var busyTries = 0
-
rimraf_(p, function CB (er) {
if (er) {
if (er.code === "EBUSY" && busyTries < exports.BUSYTRIES_MAX) {
@@ -60,102 +47,86 @@ function rimraf (p, cb) {
})
}
+// Two possible strategies.
+// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
+// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
+//
+// Both result in an extra syscall when you guess wrong. However, there
+// are likely far more normal files in the world than directories. This
+// is based on the assumption that a the average number of files per
+// directory is >= 1.
+//
+// If anyone ever complains about this, then I guess the strategy could
+// be made configurable somehow. But until then, YAGNI.
function rimraf_ (p, cb) {
- fs[lstat](p, function (er, s) {
- if (er) {
- // already gone
- if (er.code === "ENOENT") return cb()
- // some other kind of error, permissions, etc.
- return cb(er)
- }
-
- return rm_(p, s, false, cb)
+ fs.unlink(p, function (er) {
+ if (er && er.code === "ENOENT")
+ return cb()
+ if (er && (er.code === "EPERM" || er.code === "EISDIR"))
+ return rmdir(p, er, cb)
+ return cb(er)
})
}
-
-var myGid = function myGid () {
- var g = process.getuid && process.getgid()
- myGid = function myGid () { return g }
- return g
-}
-
-var myUid = function myUid () {
- var u = process.getuid && process.getuid()
- myUid = function myUid () { return u }
- return u
-}
-
-
-function writable (s) {
- var mode = s.mode || 0777
- , uid = myUid()
- , gid = myGid()
- return (mode & 0002)
- || (gid === s.gid && (mode & 0020))
- || (uid === s.uid && (mode & 0200))
-}
-
-function rm_ (p, s, didWritableCheck, cb) {
- if (!didWritableCheck && !writable(s)) {
- // make file writable
- // user/group/world, doesn't matter at this point
- // since it's about to get nuked.
- return fs.chmod(p, s.mode | 0222, function (er) {
- if (er) return cb(er)
- rm_(p, s, true, cb)
- })
- }
-
- if (!s.isDirectory()) {
- return fs.unlink(p, cb)
- }
-
- // directory
- fs.readdir(p, function (er, files) {
- if (er) return cb(er)
- asyncForEach(files.map(function (f) {
- return path.join(p, f)
- }), function (file, cb) {
- rimraf(file, cb)
- }, function (er) {
- if (er) return cb(er)
- fs.rmdir(p, cb)
- })
+function rmdir (p, originalEr, cb) {
+ // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
+ // if we guessed wrong, and it's not a directory, then
+ // raise the original error.
+ fs.rmdir(p, function (er) {
+ if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST"))
+ rmkids(p, cb)
+ else if (er && er.code === "ENOTDIR")
+ cb(originalEr)
+ else
+ cb(er)
})
}
-function asyncForEach (list, fn, cb) {
- if (!list.length) cb()
- var c = list.length
- , errState = null
- list.forEach(function (item, i, list) {
- fn(item, function (er) {
- if (errState) return
- if (er) return cb(errState = er)
- if (-- c === 0) return cb()
+function rmkids(p, cb) {
+ fs.readdir(p, function (er, files) {
+ if (er)
+ return cb(er)
+ var n = files.length
+ if (n === 0)
+ return fs.rmdir(p, cb)
+ var errState
+ files.forEach(function (f) {
+ rimraf(path.join(p, f), function (er) {
+ if (errState)
+ return
+ if (er)
+ return cb(errState = er)
+ if (--n === 0)
+ fs.rmdir(p, cb)
+ })
})
})
}
-// this looks simpler, but it will fail with big directory trees,
-// or on slow stupid awful cygwin filesystems
+// this looks simpler, and is strictly *faster*, but will
+// tie up the JavaScript thread and fail on excessively
+// deep directory trees.
function rimrafSync (p) {
try {
- var s = fs[lstatSync](p)
+ fs.unlinkSync(p)
} catch (er) {
- if (er.code === "ENOENT") return
- throw er
- }
-
- if (!writable(s)) {
- fs.chmodSync(p, s.mode | 0222)
+ if (er.code === "ENOENT")
+ return
+ if (er.code !== "EPERM" && er.code !== "EISDIR")
+ throw er
+ try {
+ fs.rmdirSync(p)
+ } catch (er2) {
+ if (er2.code === "ENOENT")
+ return
+ if (er2.code === "ENOTDIR")
+ throw er
+ if (er2.code === "ENOTEMPTY") {
+ fs.readdirSync(p).forEach(function (f) {
+ rimrafSync(path.join(p, f))
+ })
+ fs.rmdirSync(p)
+ }
+ }
}
-
- if (!s.isDirectory()) return fs.unlinkSync(p)
-
- fs.readdirSync(p).forEach(function (f) {
- rimrafSync(path.join(p, f))
- })
- fs.rmdirSync(p)
}

0 comments on commit 51fbb0b

Please sign in to comment.