0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

fixing some race conditions

This commit is contained in:
Alex Kocharin 2013-06-22 04:19:46 +04:00
parent 61727a771e
commit 27844cd358
2 changed files with 7 additions and 3 deletions

View file

@ -19,7 +19,11 @@ function make_directories(dest, cb) {
function write(dest, data, cb) { function write(dest, data, cb) {
var safe_write = function(cb) { var safe_write = function(cb) {
fs.writeFile(dest, data, cb); var tmpname = dest + '.tmp' + String(Math.random()).substr(2);
fs.writeFile(tmpname, data, function(err) {
if (err) return cb(err);
return fs.rename(tmpname, dest, cb);
});
} }
safe_write(function(err) { safe_write(function(err) {
@ -99,7 +103,7 @@ Storage.prototype.read = function(name, cb) {
Storage.prototype.read_json = function(name, cb) { Storage.prototype.read_json = function(name, cb) {
read(this.path + '/' + name, function(err, res) { read(this.path + '/' + name, function(err, res) {
if (err) return cb(err); if (err) return cb(err);
cb(null, JSON.parse(res)); cb(null, JSON.parse(res.toString('utf8')));
}); });
} }

View file

@ -92,7 +92,7 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
// if tag is updated to reference latter version, that's fine // if tag is updated to reference latter version, that's fine
var need_change = var need_change =
(data['dist-tags'][tag] == null) || (data['dist-tags'][tag] == null) ||
(!semver.gt(newdata['dist-tags'][tag], data['dist-tags'][tag])); (!semver.gte(newdata['dist-tags'][tag], data['dist-tags'][tag]));
if (need_change) { if (need_change) {
change = true; change = true;