diff options
author | isaacs <i@izs.me> | 2010-08-24 10:41:37 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-24 10:41:37 +0400 |
commit | 98fa3f2b83c57f25045a3fb1a076da4f160d7c7d (patch) | |
tree | 410d110a481ac8bd994a48dccdfd64f8ee917757 | |
parent | 3e58d4a0d6a19cce77e1c544e9aefeaad08f9930 (diff) |
a better way to roll back publishes
-rw-r--r-- | lib/utils/registry/publish.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/utils/registry/publish.js b/lib/utils/registry/publish.js index 08479991d..2901be184 100644 --- a/lib/utils/registry/publish.js +++ b/lib/utils/registry/publish.js @@ -14,6 +14,7 @@ var request = require("./request") , url = require("url") function publish (data, cb) { + cb = rollbackFailure(data, cb) // add the dist-url to the data, pointing at the tarball. // if the {name} isn't there, then create it. // if the {version} is already there, then fail. @@ -64,27 +65,28 @@ function publish (data, cb) { if (er) return cb(er) var rev = d && ("-rev/"+d._rev) , tarball = path.join(npm.cache, data.name, data.version, "package.tgz") - log(tarball, "tarball") + log.verbose(tarball, "tarball") attURI += "/" + rev upload(attURI, tarball, function (er) { - log("back from upload", "publish") - if (er) { - log("Couldn't send tarball", "publish fail") - return fail(cb, er) - } - cb() + log("uploaded", "publish") + if (er) log.error("Couldn't send tarball", "publish fail") + cb(er) }) }) }) }) } -function fail (cb, er) { - log(er, "publish fail") - npm.commands.unpublish([data.name, data.version], function (er2, ok) { - if (er2) return log.er(cb, - "Invalid data in registry! Please report this error\n")(er2) - log("Successfully unpublished", "publish fail") +function rollbackFailure (data, cb) { return function (er) { + if (!er) return cb() + npm.ROLLBACK = true + log.error(er, "publish failed") + log("rollback", "publish failed") + npm.commands.unpublish([data.name, data.version], function (er_) { + if (er_) { + log.error(er_, "rollback failed") + log.error("Invalid data in registry! Please report this.", "rollback failed") + } else log("rolled back", "publish failed") cb(er) }) -} +}} |