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:
parent
61727a771e
commit
27844cd358
2 changed files with 7 additions and 3 deletions
|
@ -19,7 +19,11 @@ function make_directories(dest, cb) {
|
|||
|
||||
function write(dest, data, 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) {
|
||||
|
@ -99,7 +103,7 @@ Storage.prototype.read = function(name, cb) {
|
|||
Storage.prototype.read_json = function(name, cb) {
|
||||
read(this.path + '/' + name, function(err, res) {
|
||||
if (err) return cb(err);
|
||||
cb(null, JSON.parse(res));
|
||||
cb(null, JSON.parse(res.toString('utf8')));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
|
|||
// if tag is updated to reference latter version, that's fine
|
||||
var need_change =
|
||||
(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) {
|
||||
change = true;
|
||||
|
|
Loading…
Reference in a new issue