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