Permalink
Browse files

rollback installation on failure

  • Loading branch information...
1 parent 80063a8 commit 885d4fed102835b3c1a217874b295f6881510ea0 @isaacs isaacs committed Mar 18, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/install.js
View
@@ -294,11 +294,20 @@ function checkGit_ (folder, cb) {
})
}
-function write (target, targetFolder, previously, cb) {
+function write (target, targetFolder, previously, cb_) {
var up = !npm.config.get("global") || npm.config.get("unsafe-perm")
, user = up ? null : npm.config.get("user")
, group = up ? null : npm.config.get("group")
+ function cb (er, data) {
+ if (!er) return cb_(er, data)
+ log.error(er, "error installing "+target._id)
+ npm.commands.unbuild([targetFolder], function (er2) {
+ if (er2) log.error(er2, "error rolling back "+target._id)
+ return cb_(er, data)
+ })
+ }
+
chain
( [ npm.commands.unbuild, [targetFolder] ]
, [ cache.unpack, target.name, target.version, targetFolder
@@ -318,9 +327,8 @@ function write (target, targetFolder, previously, cb) {
}), targetFolder, newPrev, false, function (er) {
log.verbose(targetFolder, "about to build")
if (er) return cb(er)
- chain([[npm.commands.build, [targetFolder]]].concat(cb))
+ npm.commands.build([targetFolder], cb)
})
}
- , cb
- )
+ , cb )
}

0 comments on commit 885d4fe

Please sign in to comment.