Skip to content

Commit ea763fd

Browse files
committed
File out - create dirs synchronously to ensure they exist
Fixes node-red#1489
1 parent e762b7f commit ea763fd

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

nodes/core/storage/50-file.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ module.exports = function(RED) {
4949
else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
5050
var dir = path.dirname(filename);
5151
if (node.createDir) {
52-
fs.ensureDir(dir, function(err) {
53-
if (err) { node.error(RED._("file.errors.createfail",{error:err.toString()}),msg); }
54-
});
52+
try {
53+
fs.ensureDirSync(dir);
54+
} catch(err) {
55+
node.error(RED._("file.errors.createfail",{error:err.toString()}),msg);
56+
return;
57+
}
5558
}
5659

5760
var data = msg.payload;
@@ -60,11 +63,11 @@ module.exports = function(RED) {
6063
}
6164
if (typeof data === "boolean") { data = data.toString(); }
6265
if (typeof data === "number") { data = data.toString(); }
63-
if ((this.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
66+
if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
6467
node.data.push(Buffer.from(data));
6568

6669
while (node.data.length > 0) {
67-
if (this.overwriteFile === "true") {
70+
if (node.overwriteFile === "true") {
6871
node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
6972
node.wstream.on("error", function(err) {
7073
node.error(RED._("file.errors.writefail",{error:err.toString()}),msg);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"express": "4.16.2",
4646
"express-session": "1.15.6",
4747
"follow-redirects": "1.3.0",
48-
"fs-extra": "1.0.0",
48+
"fs-extra": "5.0.0",
4949
"fs.notify": "0.0.4",
5050
"hash-sum": "1.0.2",
5151
"i18next": "1.10.6",

0 commit comments

Comments
 (0)