node8: get rid of node < 0.7 compatibility when deleting files.

- path.exists() is no longer part of nodejs
- fs.exists() is deprecated (as of nodejs >= 8)
- checking a file for existence before using it is open to raca condition. It is
  preferable to go ahead and use the file, and eventually handle the error
- we can afford two simple synchronous fs operations here
This commit is contained in:
muxator 2019-02-19 00:48:50 +01:00 committed by muxator
parent 6d36bb2c53
commit 59a6f2e9b8

View file

@ -292,16 +292,19 @@ exports.doImport = function(req, res, padId)
return; return;
} }
//for node < 0.7 compatible try {
var fileExists = fs.exists || path.exists; fs.unlinkSync(srcFile);
async.parallel([ } catch (e) {
function(callback){ console.log(e);
fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); }); }
},
function(callback){ try {
fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); }); fs.unlinkSync(destFile);
} } catch (e) {
], callback); console.log(e);
}
callback();
} }
], function(err) { ], function(err) {
var status = "ok"; var status = "ok";