mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
localfilesystem - ensure folder is present before write (e.g. flows file not in user folder)
This commit is contained in:
parent
72deee5d74
commit
a4af7b8e21
@ -15,6 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
|
var fspath = require('path');
|
||||||
var when = require('when');
|
var when = require('when');
|
||||||
var nodeFn = require('when/node/function');
|
var nodeFn = require('when/node/function');
|
||||||
|
|
||||||
@ -85,6 +86,11 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return when.promise(function(resolve,reject) {
|
return when.promise(function(resolve,reject) {
|
||||||
|
fs.ensureDir(fspath.dirname(path), (err)=>{
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var stream = fs.createWriteStream(path);
|
var stream = fs.createWriteStream(path);
|
||||||
stream.on('open',function(fd) {
|
stream.on('open',function(fd) {
|
||||||
stream.write(content,'utf8',function() {
|
stream.write(content,'utf8',function() {
|
||||||
@ -100,6 +106,7 @@ module.exports = {
|
|||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
readFile: readFile,
|
readFile: readFile,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user