mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix race condition on saving config
This commit is contained in:
@@ -118,6 +118,7 @@ module.exports = {
|
||||
getNodeConfigs: registry.getNodeConfigs,
|
||||
getNodeConfig: registry.getNodeConfig,
|
||||
clearRegistry: registry.clear,
|
||||
cleanNodeList: registry.cleanNodeList,
|
||||
|
||||
// Flow handling
|
||||
loadFlows: flows.load,
|
||||
|
@@ -69,7 +69,11 @@ var registry = (function() {
|
||||
nodeList[i] = n;
|
||||
}
|
||||
}
|
||||
settings.set("nodes",nodeList);
|
||||
if (settings.available()) {
|
||||
return settings.set("nodes",nodeList);
|
||||
} else {
|
||||
return when.reject("Settings unavailable");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -271,7 +275,22 @@ var registry = (function() {
|
||||
return filterNodeInfo(config);
|
||||
},
|
||||
|
||||
saveNodeList: saveNodeList
|
||||
saveNodeList: saveNodeList,
|
||||
|
||||
cleanNodeList: function() {
|
||||
var removed = false;
|
||||
for (var id in nodeConfigs) {
|
||||
if (nodeConfigs.hasOwnProperty(id)) {
|
||||
if (nodeConfigs[id].module && !nodeModules[nodeConfigs[id].module]) {
|
||||
registry.removeNode(id);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removed) {
|
||||
saveNodeList();
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -547,10 +566,12 @@ function load(defaultNodesDir,disableNodePathScan) {
|
||||
when.settle(promises).then(function(results) {
|
||||
// Trigger a load of the configs to get it precached
|
||||
registry.getAllNodeConfigs();
|
||||
|
||||
if (settings.available()) {
|
||||
registry.saveNodeList();
|
||||
resolve(registry.saveNodeList());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -608,11 +629,12 @@ function loadNodeList(nodes) {
|
||||
});
|
||||
|
||||
return when.settle(promises).then(function(results) {
|
||||
registry.saveNodeList();
|
||||
var list = results.map(function(r) {
|
||||
return filterNodeInfo(r.value);
|
||||
return registry.saveNodeList().then(function() {
|
||||
var list = results.map(function(r) {
|
||||
return filterNodeInfo(r.value);
|
||||
});
|
||||
return list;
|
||||
});
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -666,5 +688,6 @@ module.exports = {
|
||||
disableNode: registry.disableNodeSet,
|
||||
|
||||
addModule: addModule,
|
||||
removeModule: registry.removeModule
|
||||
removeModule: registry.removeModule,
|
||||
cleanNodeList: registry.cleanNodeList
|
||||
}
|
||||
|
@@ -330,13 +330,19 @@ function start() {
|
||||
var promises = [];
|
||||
for (i in missingModules) {
|
||||
if (missingModules.hasOwnProperty(i)) {
|
||||
util.log(" - "+i+": "+missingModules[i].join(", "));
|
||||
installModule(i).otherwise(function(err) {
|
||||
// Error already reported. Need the otherwise handler
|
||||
// to stop the error propagating any further
|
||||
});
|
||||
util.log("[red] - "+i+": "+missingModules[i].join(", "));
|
||||
if (settings.autoInstallModules) {
|
||||
installModule(i).otherwise(function(err) {
|
||||
// Error already reported. Need the otherwise handler
|
||||
// to stop the error propagating any further
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!settings.autoInstallModules) {
|
||||
util.log("[red] Removing modules from config");
|
||||
redNodes.cleanNodeList();
|
||||
}
|
||||
}
|
||||
defer.resolve();
|
||||
|
||||
|
@@ -216,7 +216,12 @@ var localfilesystem = {
|
||||
if (fs.existsSync(globalSettingsFile)) {
|
||||
return nodeFn.call(fs.readFile,globalSettingsFile,'utf8').then(function(data) {
|
||||
if (data) {
|
||||
return JSON.parse(data);
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch(err) {
|
||||
util.log("[red] Corrupted config detected - resetting");
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
Reference in New Issue
Block a user