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) {
var promises = [];
var validFiles = [];
files.forEach(function(file) {
var fullPath = fspath.join(path,file);
var stats = fs.lstatSync(fullPath);
if (stats.isDirectory()) {
validFiles.push(file);
promises.push(getFlowsFromPath(fullPath));
} else if (/\.json$/.test(file)){
validFiles.push(file);
promises.push(Promise.resolve(file.split(".")[0]))
}
})
if (files) {
files.forEach(function(file) {
var fullPath = fspath.join(path,file);
var stats = fs.lstatSync(fullPath);
if (stats.isDirectory()) {
validFiles.push(file);
promises.push(getFlowsFromPath(fullPath));
} else if (/\.json$/.test(file)){
validFiles.push(file);
promises.push(Promise.resolve(file.split(".")[0]))
}
})
}
var i=0;
Promise.all(promises).then(function(results) {
results.forEach(function(r) {