Skip to content

Commit

Permalink
install: Add scaffolding for commit half of rollback/commit
Browse files Browse the repository at this point in the history
PR-URL: npm#8859
  • Loading branch information
iarna committed Jul 10, 2015
1 parent 32e6bbd commit 31f794b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Installer.prototype.run = function (cb) {
[this.newTracker(log, 'rollbackFailedOptional', 1)],
[this, this.rollbackFailedOptional, staging, this.todo],
[this, this.finishTracker, 'rollbackFailedOptional'],
[this, this.commit, staging, this.todo],
[this.newTracker(log, 'runTopLevelLifecycles', 2)],
[this, this.runTopLevelLifecycles],
[this, this.finishTracker, 'runTopLevelLifecycles'])
Expand Down Expand Up @@ -452,6 +453,12 @@ Installer.prototype.executeActions = function (cb) {
[doParallelActions, 'extract', staging, todo, cg.newGroup('extract', 10)],
[doParallelActions, 'preinstall', staging, todo, trackLifecycle.newGroup('preinstall')],
[doReverseSerialActions, 'remove', staging, todo, cg.newGroup('remove')],
// FIXME: We do this here to commit the removes prior to trying to move
// anything into place. Once we can rollback removes we should find
// a better solution for this.
// This is to protect against cruft in the node_modules folder (like dot files)
// that stop it from being removed.
[this, this.commit, staging, this.todo],
[doSerialActions, 'move', staging, todo, cg.newGroup('move')],
[doSerialActions, 'finalize', staging, todo, cg.newGroup('finalize')],
[doSerialActions, 'build', staging, todo, trackLifecycle.newGroup('build')],
Expand Down Expand Up @@ -488,6 +495,18 @@ Installer.prototype.rollbackFailedOptional = function (staging, actionsToRun, cb
}, cb)
}

Installer.prototype.commit = function (staging, actionsToRun, cb) {
var toCommit = actionsToRun.map(function (action) { return action[1] }).filter(function (pkg) { return !pkg.failed && pkg.commit })
asyncMap(toCommit, function (pkg, next) {
asyncMap(pkg.commit, function (commit, done) {
commit(staging, pkg, done)
}, function () {
pkg.commit = []
next.apply(null, arguments)
})
}, cb)
}

Installer.prototype.runTopLevelLifecycles = function (cb) {
validate('F', arguments)
if (this.failing) return cb()
Expand Down
4 changes: 4 additions & 0 deletions lib/install/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Object.keys(actions).forEach(function (actionName) {
if (!pkg.rollback) pkg.rollback = []
pkg.rollback.unshift(action.rollback)
}
if (action.commit) {
if (!pkg.commit) pkg.commit = []
pkg.commit.push(action.commit)
}
return action(top, buildpath, pkg, log, andFinishTracker(log, andAddParentToErrors(pkg.parent, andHandleOptionalDepErrors(pkg, next))))
}
})
Expand Down

0 comments on commit 31f794b

Please sign in to comment.