diff options
author | Rebecca Turner <me@re-becca.org> | 2015-06-15 18:55:12 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:27:15 +0300 |
commit | e2aeee74c2c1cb465d5e76f3dd38477c1e0d6e30 (patch) | |
tree | beaf5e1659a1ffd155303ac363485188a046e380 | |
parent | a570d714c5324b8a8ca6bca3e53760858454054c (diff) |
rollback: Cleanup empty parents when rolling back installs
-rw-r--r-- | lib/install/action/finalize.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/install/action/finalize.js b/lib/install/action/finalize.js index b5088f6c6..31d285e34 100644 --- a/lib/install/action/finalize.js +++ b/lib/install/action/finalize.js @@ -77,5 +77,18 @@ module.exports = function (top, buildpath, pkg, log, next) { } module.exports.rollback = function (buildpath, pkg, next) { - rimraf(pkg.path, next) + var top = path.resolve(buildpath, '..') + rimraf(pkg.path, function () { + removeEmptyParents(pkg.path) + }) + function removeEmptyParents (pkgdir) { + if (path.relative(top, pkgdir)[0] === '.') return next() + require('npmlog').warn('r','removing', pkgdir) + fs.rmdir(pkgdir, function (er) { + require('npmlog').warn('r','er', er.code) + // FIXME: Make sure windows does what we want here + if (er && er.code !== 'ENOENT') return next() + removeEmptyParents(path.resolve(pkgdir, '..')) + }) + } } |