|
|
|
@ -105,7 +105,7 @@ Persistence.prototype.persistCachedDatabase = function (cb) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
function (cb) { |
|
|
|
|
fs.exists(self.tempFilename, function (exists) { |
|
|
|
|
if (exists) { |
|
|
|
|
if (exists) { // Shouldn't happen since ensureDatafileIntegrity removes the temp datafile
|
|
|
|
|
fs.unlink(self.tempFilename, function (err) { return cb(err); }); |
|
|
|
|
} else { |
|
|
|
|
return cb(); |
|
|
|
@ -113,19 +113,27 @@ Persistence.prototype.persistCachedDatabase = function (cb) { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
, function (cb) { |
|
|
|
|
console.log("==== 3"); |
|
|
|
|
fs.rename(self.filename, self.tempFilename, function (err) { |
|
|
|
|
console.log("==== 4"); |
|
|
|
|
|
|
|
|
|
if (err) { return cb(err); } |
|
|
|
|
fs.writeFile(self.filename, toPersist, function (err) { |
|
|
|
|
console.log("==== 5"); |
|
|
|
|
if (err) { return cb(err); } |
|
|
|
|
fs.exists(self.filename, function (exists) { |
|
|
|
|
if (exists) { |
|
|
|
|
fs.rename(self.filename, self.tempFilename, function (err) { return cb(err); }); |
|
|
|
|
} else { |
|
|
|
|
return cb(); |
|
|
|
|
} |
|
|
|
|
});
|
|
|
|
|
} |
|
|
|
|
, function (cb) { |
|
|
|
|
fs.writeFile(self.filename, toPersist, function (err) { return cb(err); }); |
|
|
|
|
} |
|
|
|
|
, function (cb) { |
|
|
|
|
fs.exists(self.tempFilename, function (exists) { |
|
|
|
|
if (exists) { |
|
|
|
|
fs.unlink(self.tempFilename, function (err) { return cb(err); }); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
return cb(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
], function (err) { return callback(err); }) |
|
|
|
|
], function (err) { if (err) { return callback(err); } else { return callback(null); } }) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|