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

Prevent crash when coreNodesDir is empty (#2831)

* Fix for HTTP-Request not sending body for GET

Background in SO question:
https://stackoverflow.com/q/60356824/504554

* Prevent crash when coreNodesDir points to empty dir

This should prevent a crash when you point to an empty core nodes
directory.

* Matching upstream master
This commit is contained in:
Ben Hardill 2021-01-25 10:56:23 +00:00 committed by GitHub
parent 06ceb056f3
commit ca44af0625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,17 +28,19 @@ function getFlowsFromPath(path) {
fs.readdir(path,function(err,files) { fs.readdir(path,function(err,files) {
var promises = []; var promises = [];
var validFiles = []; var validFiles = [];
files.forEach(function(file) { if (files) {
var fullPath = fspath.join(path,file); files.forEach(function(file) {
var stats = fs.lstatSync(fullPath); var fullPath = fspath.join(path,file);
if (stats.isDirectory()) { var stats = fs.lstatSync(fullPath);
validFiles.push(file); if (stats.isDirectory()) {
promises.push(getFlowsFromPath(fullPath)); validFiles.push(file);
} else if (/\.json$/.test(file)){ promises.push(getFlowsFromPath(fullPath));
validFiles.push(file); } else if (/\.json$/.test(file)){
promises.push(Promise.resolve(file.split(".")[0])) validFiles.push(file);
} promises.push(Promise.resolve(file.split(".")[0]))
}) }
})
}
var i=0; var i=0;
Promise.all(promises).then(function(results) { Promise.all(promises).then(function(results) {
results.forEach(function(r) { results.forEach(function(r) {