Permalink
Browse files

broken. whatever. rebase this away.

  • Loading branch information...
1 parent 6f17a04 commit d8c306ca91e9f17be690efa17b5bd1f991556f96 @isaacs isaacs committed Aug 26, 2010
Showing with 33 additions and 6 deletions.
  1. +33 −6 lib/cache.js
View
@@ -140,13 +140,40 @@ function addLocal (p, cb) {
else addLocalTarball(p, cb)
})
}
-function addLocalTarball (p, cb) {
- // if it's a tar, and not in place,
- // then unzip to .tmp, add the tmp folder, and clean up tmp
+
+function cp (from, to, cb) {
+ var fstr = fs.createReadStream(from)
+ , tstr = fs.createWriteStream(to)
+ , errState = null
+ fstr.on("error", erFn)
+ tstr.on("error", erFn)
+ function erFn (er) {
+ if (errState) return
+ errState = er
+ try { // this will make the pump abort
+ fstr.forceClose()
+ tstr.forceClose()
+ } catch (ex) {}
+ }
+ sys.pump(fstr, tstr, function () { cb(errState) })
+}
+function addLocalTarball (p, data, cb) {
+ // unpack to a temp folder, then read the contents of the package.json
+ // rm the current proper cache folder, then move the folder and tarball
+ // into place.
var tmp = path.join(npm.tmp, Date.now() + "-" + Math.random())
- if (p.indexOf(npm.cache) !== 0) {
- return unpackTar(p, tmp, function (er) {
- if (er) return log.er(cb, "Failed to unpack "+p)(er)
+ // move it aside, in case it's in the .cache already.
+ fs.rename(p, tmp+".tgz", function (er) {
+ if (er) return log.er(cb, "failed moving "+p+" to "+tmp)(er)
+ p = tmp + ".tgz"
+
+
+
+ unpackTar(p, tmp, function (er) {
+ if (er) return log.er(cb, "Failed to unpack "+p)(er)
+
+
+
addLocalDirectory(tmp, function (er, data) {
if (er) cb(er)
rm(tmp, function (er) {

0 comments on commit d8c306c

Please sign in to comment.