Skip to content

Commit

Permalink
Fix npm#1555 Queue tar operations for windows
Browse files Browse the repository at this point in the history
*Really* need to get a js tar implementation in there asap.
  • Loading branch information
isaacs committed Oct 15, 2011
1 parent 9047445 commit 0f7ffc2
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions lib/utils/tar.js
Expand Up @@ -24,22 +24,41 @@ exports.pack = pack
exports.unpack = unpack exports.unpack = unpack
exports.makeList = makeList exports.makeList = makeList


var packQueue = []
, packing = false


function pack (targetTarball, folder, pkg, dfc, cb) { function pack (targetTarball, folder, pkg, dfc, cb_) {
if (typeof cb !== "function") cb = dfc, dfc = true if (typeof cb_ !== "function") cb_ = dfc, dfc = true
folder = path.resolve(process.cwd(), folder) folder = path.resolve(process.cwd(), folder)
if (typeof pkg === "function") { if (typeof pkg === "function") {
cb = pkg, pkg = null cb_ = pkg, pkg = null
return readJson(path.resolve(folder, "package.json"), function (er, pkg) { return readJson(path.resolve(folder, "package.json"), function (er, pkg) {
if (er) return log.er(cb, "Couldn't find package.json in "+folder)(er) if (er) return log.er(cb_, "Couldn't find package.json in "+folder)(er)
pack(targetTarball, folder, pkg, dfc, cb) pack(targetTarball, folder, pkg, dfc, cb_)
}) })
} }
log.verbose(folder+" "+targetTarball, "pack") log.verbose(folder+" "+targetTarball, "pack")
var parent = path.dirname(folder) var parent = path.dirname(folder)
, addFolder = path.basename(folder) , addFolder = path.basename(folder)


cb = log.er(cb, "Failed creating the tarball.") cb_ = log.er(cb_, "Failed creating the tarball.")


// XXX Rip out all this crap and use a tar get gets along with windows.
if (packing && process.platform === "win32") {
packQueue.push([targetTarball, folder, pkg, dfc, cb_])
return
}

packing = true
function cb (er, data) {
packing = false
var next = packQueue.shift()
if (next) process.nextTick(function () {
pack.apply(null, next)
})
cb_(er, data)
}


var confEx = npm.config.get("ignore") var confEx = npm.config.get("ignore")
makeList(folder, pkg, dfc, function (er, files, cleanup) { makeList(folder, pkg, dfc, function (er, files, cleanup) {
Expand Down Expand Up @@ -113,7 +132,26 @@ function unpack (tarball, unpackTarget, dMode, fMode, uid, gid, cb) {
}) })
} }


function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) { // XXX Rip all this crap out and use a tar that gets along with windows.
var unpackQueue = []
, unpacking = false

function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb_ ) {
if (unpacking && process.platform === "win32") {
unpackQueue.push([tarball, unpackTarget, dMode, fMode, uid, gid, cb_])
return
}

unpacking = true
function cb (er, data) {
unpacking = false
var next = unpackQueue.shift()
if (next) process.nextTick(function () {
unpack_.apply(null, next)
})
cb_(er, data)
}

// If the desired target is /path/to/foo, // If the desired target is /path/to/foo,
// then unpack into /path/to/.foo.npm/{something} // then unpack into /path/to/.foo.npm/{something}
// rename that to /path/to/foo, and delete /path/to/.foo.npm // rename that to /path/to/foo, and delete /path/to/.foo.npm
Expand Down

0 comments on commit 0f7ffc2

Please sign in to comment.