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:
parent
b307492487
commit
2845475e3f
@ -514,11 +514,6 @@ function saveFlows(flows) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flowsFileExists = true;
|
flowsFileExists = true;
|
||||||
|
|
||||||
try {
|
|
||||||
fs.renameSync(flowsFullPath,flowsFileBackup);
|
|
||||||
} catch(err) {
|
|
||||||
}
|
|
||||||
|
|
||||||
var flowData;
|
var flowData;
|
||||||
|
|
||||||
@ -527,7 +522,7 @@ function saveFlows(flows) {
|
|||||||
} else {
|
} else {
|
||||||
flowData = JSON.stringify(flows);
|
flowData = JSON.stringify(flows);
|
||||||
}
|
}
|
||||||
return util.writeFile(flowsFullPath, flowData);
|
return util.writeFile(flowsFullPath, flowData, flowsFileBackup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCredentials() {
|
function getCredentials() {
|
||||||
@ -539,17 +534,13 @@ function saveCredentials(credentials) {
|
|||||||
return when.resolve();
|
return when.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
fs.renameSync(credentialsFile,credentialsFileBackup);
|
|
||||||
} catch(err) {
|
|
||||||
}
|
|
||||||
var credentialData;
|
var credentialData;
|
||||||
if (settings.flowFilePretty) {
|
if (settings.flowFilePretty) {
|
||||||
credentialData = JSON.stringify(credentials,null,4);
|
credentialData = JSON.stringify(credentials,null,4);
|
||||||
} else {
|
} else {
|
||||||
credentialData = JSON.stringify(credentials);
|
credentialData = JSON.stringify(credentials);
|
||||||
}
|
}
|
||||||
return util.writeFile(credentialsFile, credentialData);
|
return util.writeFile(credentialsFile, credentialData, credentialsFileBackup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFlowFilename() {
|
function getFlowFilename() {
|
||||||
|
@ -22,12 +22,14 @@ var log = require("../../log");
|
|||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
|
|
||||||
var globalSettingsFile;
|
var globalSettingsFile;
|
||||||
|
var globalSettingsBackup;
|
||||||
var settings;
|
var settings;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: function(_settings) {
|
init: function(_settings) {
|
||||||
settings = _settings;
|
settings = _settings;
|
||||||
globalSettingsFile = fspath.join(settings.userDir,".config.json");
|
globalSettingsFile = fspath.join(settings.userDir,".config.json");
|
||||||
|
globalSettingsBackup = fspath.join(settings.userDir,".config.json.backup");
|
||||||
},
|
},
|
||||||
getSettings: function() {
|
getSettings: function() {
|
||||||
return when.promise(function(resolve,reject) {
|
return when.promise(function(resolve,reject) {
|
||||||
@ -47,6 +49,6 @@ module.exports = {
|
|||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return when.resolve();
|
||||||
}
|
}
|
||||||
return util.writeFile(globalSettingsFile,JSON.stringify(newSettings,null,1));
|
return util.writeFile(globalSettingsFile,JSON.stringify(newSettings,null,1),globalSettingsBackup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,16 @@ module.exports = {
|
|||||||
* This forces a fsync before completing to ensure
|
* This forces a fsync before completing to ensure
|
||||||
* the write hits disk.
|
* 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) {
|
return when.promise(function(resolve,reject) {
|
||||||
var stream = fs.createWriteStream(path);
|
var stream = fs.createWriteStream(path);
|
||||||
stream.on('open',function(fd) {
|
stream.on('open',function(fd) {
|
||||||
|
Loading…
Reference in New Issue
Block a user