Closed kamil-mech closed 9 years ago
@kamil-mech looks good. Can you provide a test when this condition occurs?
I suggest applying this solution instead. I have tested and it works. What You think?
https://github.com/senecajs/seneca-level-store/commit/c15fbdea94a24a78e25637e2b114b78e6c14cdb7
/**
* Return if the folder exists, create otherwise.
*/
function ensurefolder(folder, cb){
fs.stat(folder, function(err, stat) {
if (!err && stat.isDirectory()) {
return cb();
}
fs.mkdir(folder, function(err) {
if (err && err.code === 'EEXIST') {
err = null;
}
cb(err);
});
});
}
looks good to me
Ready now. Feel free to merge.
May You please push the changes to npm? Thank You
ensurefolder tries to fs.mkdir and returns error if any occurs. The problem is when fs.mkdir returns error stating that the folder already exists. ensurefolder sends that out as an error, which causes a snowballing effect.
As ensurefolder's role is to make sure folder exists, it shouldn't really return an error saying a folder exists, right?