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

Place flows backup alongside flow file

Also backup credentials file in the same manner.
This commit is contained in:
Nick O'Leary 2015-02-04 13:45:45 +00:00
parent a08b29dbd1
commit 8443e48240
2 changed files with 17 additions and 7 deletions

View File

@ -28,7 +28,7 @@ var promiseDir = nodeFn.lift(mkdirp);
var settings; var settings;
var flowsFile; var flowsFile;
var flowsFullPath; var flowsFullPath;
var flowsPrev; var flowsFileBackup;
var credentialsFile; var credentialsFile;
var oldCredentialsFile; var oldCredentialsFile;
var userDir; var userDir;
@ -153,10 +153,17 @@ var localfilesystem = {
flowsFile = 'flows_'+require('os').hostname()+'.json'; flowsFile = 'flows_'+require('os').hostname()+'.json';
flowsFullPath = fspath.join(userDir,flowsFile); flowsFullPath = fspath.join(userDir,flowsFile);
} }
var fsext = fspath.extname(flowsFile); var ffExt = fspath.extname(flowsFullPath);
credentialsFile = fspath.join(userDir,fspath.basename(flowsFile,fsext)+"_cred"+fsext); var ffName = fspath.basename(flowsFullPath);
var ffBase = fspath.basename(flowsFullPath,ffExt);
var ffDir = fspath.dirname(flowsFullPath);
credentialsFile = fspath.join(userDir,ffBase+"_cred"+ffExt);
credentialsFileBackup = fspath.join(userDir,"."+ffBase+"_cred"+ffExt+".backup");
oldCredentialsFile = fspath.join(userDir,"credentials.json"); oldCredentialsFile = fspath.join(userDir,"credentials.json");
flowsPrev = fspath.join(userDir,"flows.backup");
flowsFileBackup = fspath.join(ffDir,"."+ffName+".backup");
libDir = fspath.join(userDir,"lib"); libDir = fspath.join(userDir,"lib");
libFlowsDir = fspath.join(libDir,"flows"); libFlowsDir = fspath.join(libDir,"flows");
@ -185,7 +192,7 @@ var localfilesystem = {
saveFlows: function(flows) { saveFlows: function(flows) {
if (fs.existsSync(flowsFullPath)) { if (fs.existsSync(flowsFullPath)) {
fs.renameSync(flowsFullPath,flowsPrev); fs.renameSync(flowsFullPath,flowsFileBackup);
} }
var flowData; var flowData;
@ -221,6 +228,9 @@ var localfilesystem = {
}, },
saveCredentials: function(credentials) { saveCredentials: function(credentials) {
if (fs.existsSync(credentialsFile)) {
fs.renameSync(credentialsFile,credentialsFileBackup);
}
var credentialData; var credentialData;
if (settings.flowFilePretty) { if (settings.flowFilePretty) {
credentialData = JSON.stringify(credentials,null,4); credentialData = JSON.stringify(credentials,null,4);

View File

@ -62,7 +62,7 @@ describe('LocalFileSystem', function() {
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
var flowFile = 'flows_'+require('os').hostname()+'.json'; var flowFile = 'flows_'+require('os').hostname()+'.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var flowFileBackupPath = path.join(userDir,"flows.backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
fs.existsSync(flowFilePath).should.be.false; fs.existsSync(flowFilePath).should.be.false;
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false;
localfilesystem.saveFlows(testFlow).then(function() { localfilesystem.saveFlows(testFlow).then(function() {
@ -114,7 +114,7 @@ describe('LocalFileSystem', function() {
var defaultFlowFilePath = path.join(userDir,defaultFlowFile); var defaultFlowFilePath = path.join(userDir,defaultFlowFile);
var flowFile = 'test.json'; var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var flowFileBackupPath = path.join(userDir,"flows.backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false;