diff --git a/.gitignore b/.gitignore index 853218a39..b23124927 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules credentials.json flows*.json +flow.backup *_cred* nodes/node-red-nodes/ .npm diff --git a/red/storage/localfilesystem.js b/red/storage/localfilesystem.js index e7832a936..5dc191768 100644 --- a/red/storage/localfilesystem.js +++ b/red/storage/localfilesystem.js @@ -27,6 +27,7 @@ var promiseDir = nodeFn.lift(mkdirp); var settings; var flowsFile; var flowsFullPath; +var flowsPrev; var credentialsFile; var oldCredentialsFile; var userDir; @@ -152,6 +153,7 @@ var localfilesystem = { var fsext = fspath.extname(flowsFile); credentialsFile = fspath.join(userDir,fspath.basename(flowsFile,fsext)+"_cred"+fsext); oldCredentialsFile = fspath.join(userDir,"credentials.json"); + flowsPrev = fspath.join(userDir,"flow.backup"); libDir = fspath.join(userDir,"lib"); libFlowsDir = fspath.join(libDir,"flows"); @@ -176,6 +178,7 @@ var localfilesystem = { }, saveFlows: function(flows) { + fs.rename(flowsFullPath,flowsPrev); return nodeFn.call(fs.writeFile, flowsFullPath, JSON.stringify(flows)); },