Permalink
Browse files

Add a config to scrub the cache before adding

This makes it work when a non-root user is publishing something
which has previously been added to the cache by a root user.
  • Loading branch information...
1 parent 56f9529 commit 38e05db81b96fd5e12a1884612833645f35749ae @isaacs isaacs committed Feb 7, 2011
Showing with 9 additions and 2 deletions.
  1. +8 −1 lib/cache.js
  2. +1 −1 lib/publish.js
View
@@ -178,7 +178,14 @@ function clean (args, cb) {
// npm cache add <pkg> <ver>
// npm cache add <tarball>
// npm cache add <folder>
-exports.add = function (pkg, ver, cb) {
+exports.add = function (pkg, ver, scrub, cb) {
+ if (typeof cb !== "function") cb = scrub, scrub = false
+ if (scrub) {
+ return clean([], function (er) {
+ if (er) return cb(er)
+ add([pkg, ver], cb)
+ })
+ }
log.verbose([pkg, ver], "cache add")
if (!cb && typeof ver === "function") cb = ver, ver = null
return add([pkg, ver], cb)
View
@@ -13,7 +13,7 @@ function publish (args, isRetry, cb) {
if (typeof cb !== "function") cb = isRetry, isRetry = false
if (args.length === 0) args = ["."]
log.verbose(args, "publish")
- npm.commands.cache.add(args[0], args[1], function (er, data) {
+ npm.commands.cache.add(args[0], args[1], true, function (er, data) {
if (er) return cb(er)
log.silly(data, "publish")
if (!data) return cb(new Error("no package.json file found"))

0 comments on commit 38e05db

Please sign in to comment.