mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-30 00:47:13 +09:00
fileOps: Fixed crash on invalid filenames, added test for it
This commit is contained in:
1 parent
e1ab5b4d91
commit
e55bf71431
2 files changed
+7
-3
No files matched your search
+5
-2
@@ -73,7 +73,9 @@ var deleteFolderRecursiveSync = function(path) {
|
||||
var deleteFolderRecursive = function(path){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(path, (err, files) => {
|
||||
if(err) reject(err);
|
||||
if(err){
|
||||
reject(err);
|
||||
} else {
|
||||
let thingsToDelete = files.length;
|
||||
files.forEach(file => {
|
||||
let curPath = path + "/" + file;
|
||||
@@ -83,7 +85,7 @@ var deleteFolderRecursive = function(path){
|
||||
// recurse
|
||||
deleteFolderRecursive(curPath).then(() => {
|
||||
whenFilesDeleted();
|
||||
});
|
||||
}).catch(e => console.log(e));
|
||||
} else {
|
||||
fs.unlink(curPath, () => {
|
||||
// console.log("Deleted "+curPath);
|
||||
@@ -104,6 +106,7 @@ var deleteFolderRecursive = function(path){
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+2
-1
@@ -115,6 +115,7 @@ describe("fileOps.js", function(){
|
||||
describe("fileOps.deleteFolderRecursive(path)", function(){
|
||||
it("deletes a folder and all files and folders in it, just like sync version", async function(){
|
||||
setupTestingEnv();
|
||||
assert(fs.statSync(path.resolve(__dirname, "test")));
|
||||
let x = await fileOps.deleteFolderRecursive(path.resolve(__dirname, "test"));
|
||||
assert.throws(function(){
|
||||
fs.statSync(path.resolve(__dirname, "test"));
|
||||
@@ -122,7 +123,7 @@ describe("fileOps.js", function(){
|
||||
assert(x === undefined, "Promise version of this function does not have a return value upon success");
|
||||
return true;
|
||||
}).timeout(5000);
|
||||
it("throws like a promise if you give it an invalid path", async function(){
|
||||
it("throws like a promise does if you give it an invalid path", async function(){
|
||||
let x = await fileOps.deleteFolderRecursive("Look this path is fake!")
|
||||
.catch(e => {
|
||||
assert(e);
|
||||
|
||||
Reference in new issue
Block a user