mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Write data file atomically
This commit is contained in:
@@ -482,6 +482,14 @@ files.renameDirAlmostAtomically = function (fromDir, toDir) {
|
||||
files.rm_recursive(garbageDir);
|
||||
};
|
||||
|
||||
files.writeFileAtomically = function (filename, contents) {
|
||||
var tmpFile = path.join(
|
||||
path.dirname(filename),
|
||||
'.' + path.basename(filename) + '.' + utils.randomToken());
|
||||
fs.writeFileSync(tmpFile, contents);
|
||||
fs.renameSync(tmpFile, filename);
|
||||
};
|
||||
|
||||
// Run a program synchronously and, assuming it returns success (0),
|
||||
// return whatever it wrote to stdout, as a string. Otherwise (if it
|
||||
// did not exit gracefully and return 0) return null. As node has
|
||||
|
||||
@@ -85,7 +85,7 @@ var writePackagesToDisk = function (syncToken, collectionData) {
|
||||
var filename = config.getPackageStorage();
|
||||
// XXX think about permissions?
|
||||
files.mkdir_p(path.dirname(filename));
|
||||
fs.writeFileSync(filename, JSON.stringify(finalWrite, null, 2));
|
||||
files.writeFileAtomically(filename, JSON.stringify(finalWrite, null, 2));
|
||||
};
|
||||
|
||||
loadPackageData = function() {
|
||||
|
||||
Reference in New Issue
Block a user