From e12975cf0b7849a377ef32bf93bd647795668c93 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 25 Sep 2020 15:50:26 +0100 Subject: [PATCH] Do not remove old config.json file to ease downgrade path --- .../lib/storage/localfilesystem/settings.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/settings.js b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/settings.js index c476dc192..f7c907f2a 100644 --- a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/settings.js +++ b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/settings.js @@ -29,8 +29,24 @@ var globalSettingsBackup; var settings; async function migrateToMultipleConfigFiles() { + const nodesFilename = getSettingsFilename("nodes"); + if (fs.existsSync(nodesFilename)) { + // We have both .config.json and .config.nodes.json + // Use the more recently modified. This handles users going back to pre1.2 + // and up again. + // We can remove this logic in 1.3+ and remove the old .config.json file entirely + // + const fsStatNodes = await fs.stat(nodesFilename); + const fsStatGlobal = await fs.stat(globalSettingsFile); + if (fsStatNodes.mtimeMs > fsStatGlobal.mtimeMs) { + // .config.nodes.json is newer than .config.json - no migration needed + return; + } + } const data = await util.readFile(globalSettingsFile,globalSettingsBackup,{}); - return writeSettings(data).then( () => fs.remove(globalSettingsFile) ); + // In a later release we should remove the old settings file. But don't do + // that *yet* otherwise users won't be able to downgrade easily. + return writeSettings(data) // .then( () => fs.remove(globalSettingsFile) ); }