mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add clean to context plugin
and don't delete local context unless the context is deleted by a user
This commit is contained in:
@@ -105,12 +105,12 @@ Node.prototype.close = function(removed) {
|
||||
if (promises.length > 0) {
|
||||
return when.settle(promises).then(function() {
|
||||
if (this._context) {
|
||||
context.delete(this._alias||this.id,this.z);
|
||||
return context.delete(this._alias||this.id,this.z);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (this._context) {
|
||||
context.delete(this._alias||this.id,this.z);
|
||||
return context.delete(this._alias||this.id,this.z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@@ -70,6 +70,11 @@ function load() {
|
||||
return when.reject(new Error(log._("context.error-module-not-defined", {storage:pluginName})));
|
||||
}
|
||||
}
|
||||
for(var plugin in externalContexts){
|
||||
if(externalContexts.hasOwnProperty(plugin)){
|
||||
promises.push(externalContexts[plugin].open());
|
||||
}
|
||||
}
|
||||
if(isAlias){
|
||||
if(externalContexts.hasOwnProperty(plugins["default"])){
|
||||
externalContexts["default"] = externalContexts[plugins["default"]];
|
||||
@@ -77,11 +82,6 @@ function load() {
|
||||
return when.reject(new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]})));
|
||||
}
|
||||
}
|
||||
for(var plugin in externalContexts){
|
||||
if(externalContexts.hasOwnProperty(plugin)){
|
||||
promises.push(externalContexts[plugin].open());
|
||||
}
|
||||
}
|
||||
return when.all(promises);
|
||||
} else {
|
||||
noContextStorage = true;
|
||||
@@ -191,31 +191,35 @@ function getContext(localId,flowId) {
|
||||
}
|
||||
|
||||
function deleteContext(id,flowId) {
|
||||
var contextId = id;
|
||||
if (flowId) {
|
||||
contextId = id+":"+flowId;
|
||||
if(noContextStorage){
|
||||
var promises = [];
|
||||
var contextId = id;
|
||||
if (flowId) {
|
||||
contextId = id+":"+flowId;
|
||||
}
|
||||
delete contexts[contextId];
|
||||
return externalContexts["_"].delete(contextId);
|
||||
}else{
|
||||
return when.resolve();
|
||||
}
|
||||
for(var plugin in externalContexts){
|
||||
externalContexts[plugin].delete(contextId);
|
||||
}
|
||||
delete contexts[contextId];
|
||||
}
|
||||
|
||||
function clean(flowConfig) {
|
||||
var activeIds = {};
|
||||
var contextId;
|
||||
var node;
|
||||
var promises = [];
|
||||
for(var plugin in externalContexts){
|
||||
if(externalContexts.hasOwnProperty(plugin)){
|
||||
promises.push(externalContexts[plugin].clean(Object.keys(flowConfig.allNodes)));
|
||||
}
|
||||
}
|
||||
for (var id in contexts) {
|
||||
if (contexts.hasOwnProperty(id)) {
|
||||
var idParts = id.split(":");
|
||||
if (!flowConfig.allNodes.hasOwnProperty(idParts[0])) {
|
||||
for(var plugin in externalContexts){
|
||||
externalContexts[plugin].delete(id);
|
||||
}
|
||||
delete contexts[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
return when.all(promises);
|
||||
}
|
||||
|
||||
function close() {
|
||||
|
@@ -78,7 +78,7 @@ LocalFileSystem.prototype.close = function(){
|
||||
|
||||
LocalFileSystem.prototype.get = function (scope, key) {
|
||||
if(!this.storages[scope]){
|
||||
return undefined;
|
||||
this.storages[scope] = createStorage(this.storageBaseDir ,scope);
|
||||
}
|
||||
try{
|
||||
this.storages[scope].reload();
|
||||
@@ -105,28 +105,38 @@ LocalFileSystem.prototype.set = function(scope, key, value) {
|
||||
|
||||
LocalFileSystem.prototype.keys = function(scope) {
|
||||
if(!this.storages[scope]){
|
||||
return [];
|
||||
this.storages[scope] = createStorage(this.storageBaseDir ,scope);
|
||||
}
|
||||
return Object.keys(this.storages[scope].getData("/"));
|
||||
}
|
||||
|
||||
LocalFileSystem.prototype.delete = function(scope){
|
||||
var self = this;
|
||||
if(this.storages[scope]){
|
||||
var promise;
|
||||
this.storages[scope].delete("/");
|
||||
if(scope.indexOf(":") === -1){
|
||||
fs.removeSync(path.dirname(this.storages[scope].filename));
|
||||
}else{
|
||||
try{
|
||||
fs.statSync(this.storages[scope].filename);
|
||||
fs.unlinkSync(this.storages[scope].filename);
|
||||
}catch(err){
|
||||
console.log("deleted");
|
||||
}
|
||||
}
|
||||
delete this.storages[scope];
|
||||
return fs.remove(this.storages[scope].filename).then(function(){
|
||||
delete self.storages[scope];
|
||||
return when.resolve();
|
||||
});
|
||||
}else{
|
||||
return when.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
LocalFileSystem.prototype.clean = function(activeNodes){
|
||||
var self = this;
|
||||
return fs.readdir(self.storageBaseDir).then(function(dirs){
|
||||
return when.all(dirs.reduce(function(result, item){
|
||||
if(item !== "global" && !activeNodes.includes(item)){
|
||||
result.push(fs.remove(path.join(self.storageBaseDir,item)));
|
||||
delete self.storages[item];
|
||||
}
|
||||
return result;
|
||||
},[]));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function(config){
|
||||
return new LocalFileSystem(config);
|
||||
};
|
||||
|
@@ -58,9 +58,21 @@ Memory.prototype.keys = function(scope){
|
||||
|
||||
Memory.prototype.delete = function(scope){
|
||||
delete this.data[scope];
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
Memory.prototype.clean = function(activeNodes){
|
||||
for(var id in this.data){
|
||||
if(this.data.hasOwnProperty(id) && id !== "global"){
|
||||
var idParts = id.split(":");
|
||||
if(!activeNodes.includes(idParts[0])){
|
||||
delete this.data[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
Memory.prototype.setGlobalContext= function(seed){
|
||||
this.data["global"] = seed;
|
||||
};
|
||||
|
@@ -160,11 +160,12 @@ function setFlows(_config,type,muteLog,forceStart) {
|
||||
activeFlowConfig = newFlowConfig;
|
||||
if (forceStart || started) {
|
||||
return stop(type,diff,muteLog).then(function() {
|
||||
context.clean(activeFlowConfig);
|
||||
start(type,diff,muteLog).then(function() {
|
||||
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
|
||||
return context.clean(activeFlowConfig).then(function() {
|
||||
start(type,diff,muteLog).then(function() {
|
||||
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
|
||||
});
|
||||
return flowRevision;
|
||||
});
|
||||
return flowRevision;
|
||||
}).catch(function(err) {
|
||||
})
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user