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

File out - create dirs synchronously to ensure they exist

Fixes #1489
This commit is contained in:
Nick O'Leary 2018-01-14 00:33:25 +00:00
parent e762b7ff48
commit ea763fdfd5
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 9 additions and 6 deletions

View File

@ -49,9 +49,12 @@ module.exports = function(RED) {
else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) { else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
var dir = path.dirname(filename); var dir = path.dirname(filename);
if (node.createDir) { if (node.createDir) {
fs.ensureDir(dir, function(err) { try {
if (err) { node.error(RED._("file.errors.createfail",{error:err.toString()}),msg); } fs.ensureDirSync(dir);
}); } catch(err) {
node.error(RED._("file.errors.createfail",{error:err.toString()}),msg);
return;
}
} }
var data = msg.payload; var data = msg.payload;
@ -60,11 +63,11 @@ module.exports = function(RED) {
} }
if (typeof data === "boolean") { data = data.toString(); } if (typeof data === "boolean") { data = data.toString(); }
if (typeof data === "number") { data = data.toString(); } if (typeof data === "number") { data = data.toString(); }
if ((this.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; } if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
node.data.push(Buffer.from(data)); node.data.push(Buffer.from(data));
while (node.data.length > 0) { while (node.data.length > 0) {
if (this.overwriteFile === "true") { if (node.overwriteFile === "true") {
node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true }); node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
node.wstream.on("error", function(err) { node.wstream.on("error", function(err) {
node.error(RED._("file.errors.writefail",{error:err.toString()}),msg); node.error(RED._("file.errors.writefail",{error:err.toString()}),msg);

View File

@ -45,7 +45,7 @@
"express": "4.16.2", "express": "4.16.2",
"express-session": "1.15.6", "express-session": "1.15.6",
"follow-redirects": "1.3.0", "follow-redirects": "1.3.0",
"fs-extra": "1.0.0", "fs-extra": "5.0.0",
"fs.notify": "0.0.4", "fs.notify": "0.0.4",
"hash-sum": "1.0.2", "hash-sum": "1.0.2",
"i18next": "1.10.6", "i18next": "1.10.6",