1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Keep backup of .config.json

This commit is contained in:
Nick O'Leary 2018-03-20 00:04:36 +00:00
parent b307492487
commit 2845475e3f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 15 additions and 13 deletions

View File

@ -515,11 +515,6 @@ function saveFlows(flows) {
flowsFileExists = true;
try {
fs.renameSync(flowsFullPath,flowsFileBackup);
} catch(err) {
}
var flowData;
if (settings.flowFilePretty) {
@ -527,7 +522,7 @@ function saveFlows(flows) {
} else {
flowData = JSON.stringify(flows);
}
return util.writeFile(flowsFullPath, flowData);
return util.writeFile(flowsFullPath, flowData, flowsFileBackup);
}
function getCredentials() {
@ -539,17 +534,13 @@ function saveCredentials(credentials) {
return when.resolve();
}
try {
fs.renameSync(credentialsFile,credentialsFileBackup);
} catch(err) {
}
var credentialData;
if (settings.flowFilePretty) {
credentialData = JSON.stringify(credentials,null,4);
} else {
credentialData = JSON.stringify(credentials);
}
return util.writeFile(credentialsFile, credentialData);
return util.writeFile(credentialsFile, credentialData, credentialsFileBackup);
}
function getFlowFilename() {

View File

@ -22,12 +22,14 @@ var log = require("../../log");
var util = require("./util");
var globalSettingsFile;
var globalSettingsBackup;
var settings;
module.exports = {
init: function(_settings) {
settings = _settings;
globalSettingsFile = fspath.join(settings.userDir,".config.json");
globalSettingsBackup = fspath.join(settings.userDir,".config.json.backup");
},
getSettings: function() {
return when.promise(function(resolve,reject) {
@ -47,6 +49,6 @@ module.exports = {
if (settings.readOnly) {
return when.resolve();
}
return util.writeFile(globalSettingsFile,JSON.stringify(newSettings,null,1));
return util.writeFile(globalSettingsFile,JSON.stringify(newSettings,null,1),globalSettingsBackup);
}
}

View File

@ -78,7 +78,16 @@ module.exports = {
* This forces a fsync before completing to ensure
* the write hits disk.
*/
writeFile: function(path,content) {
writeFile: function(path,content,backupPath) {
if (backupPath) {
try {
console.log(path);
console.log(backupPath);
fs.renameSync(path,backupPath);
} catch(err) {
console.log(err);
}
}
return when.promise(function(resolve,reject) {
var stream = fs.createWriteStream(path);
stream.on('open',function(fd) {