Delete previous directory if already exists during task init

pull/121/head
Piero Toffanin 2020-08-26 15:54:32 -04:00
rodzic 9b5797b6c1
commit aeb31f6ecd
1 zmienionych plików z 10 dodań i 1 usunięć

Wyświetl plik

@ -259,7 +259,16 @@ module.exports = {
if (req.files && req.files.length > 0) {
fs.stat(destPath, (err, stat) => {
if (err && err.code === 'ENOENT') cb();
else cb(new Error(`Directory exists (should not have happened)`));
else{
// Directory already exists, this could happen
// if a previous attempt at upload failed and the user
// used set-uuid to specify the same UUID over the previous run
// Try to remove it
removeDirectory(destPath, err => {
if (err) cb(new Error(`Directory exists and we couldn't remove it.`));
else cb();
});
}
});
} else {
cb();