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

Fix race condition in .config file migration

Fixes #2724
This commit is contained in:
Nick O'Leary 2020-10-15 16:21:28 +01:00
parent 15a600c763
commit e34f4acb22
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -34,11 +34,9 @@ function checkForConfigFile(dir) {
} }
var localfilesystem = { var localfilesystem = {
init: function(_settings, runtime) { init: async function(_settings, runtime) {
settings = _settings; settings = _settings;
var promises = [];
if (!settings.userDir) { if (!settings.userDir) {
if (checkForConfigFile(process.env.NODE_RED_HOME)) { if (checkForConfigFile(process.env.NODE_RED_HOME)) {
settings.userDir = process.env.NODE_RED_HOME settings.userDir = process.env.NODE_RED_HOME
@ -49,18 +47,16 @@ var localfilesystem = {
} }
} }
if (!settings.readOnly) { if (!settings.readOnly) {
promises.push(fs.ensureDir(fspath.join(settings.userDir,"node_modules"))); await fs.ensureDir(fspath.join(settings.userDir,"node_modules"));
} }
sessions.init(settings); sessions.init(settings);
promises.push(runtimeSettings.init(settings)); await runtimeSettings.init(settings);
promises.push(library.init(settings)); await library.init(settings);
promises.push(projects.init(settings, runtime)); await projects.init(settings, runtime);
var packageFile = fspath.join(settings.userDir,"package.json"); var packageFile = fspath.join(settings.userDir,"package.json");
var packagePromise = Promise.resolve();
if (!settings.readOnly) { if (!settings.readOnly) {
packagePromise = function() {
try { try {
fs.statSync(packageFile); fs.statSync(packageFile);
} catch(err) { } catch(err) {
@ -72,10 +68,7 @@ var localfilesystem = {
}; };
return util.writeFile(packageFile,JSON.stringify(defaultPackage,"",4)); return util.writeFile(packageFile,JSON.stringify(defaultPackage,"",4));
} }
return true;
} }
}
return Promise.all(promises).then(packagePromise);
}, },