mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
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:
parent
6d36bb2c53
commit
59a6f2e9b8
1 changed files with 13 additions and 10 deletions
|
@ -292,16 +292,19 @@ exports.doImport = function(req, res, padId)
|
|||
return;
|
||||
}
|
||||
|
||||
//for node < 0.7 compatible
|
||||
var fileExists = fs.exists || path.exists;
|
||||
async.parallel([
|
||||
function(callback){
|
||||
fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); });
|
||||
},
|
||||
function(callback){
|
||||
fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); });
|
||||
}
|
||||
], callback);
|
||||
try {
|
||||
fs.unlinkSync(srcFile);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.unlinkSync(destFile);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
], function(err) {
|
||||
var status = "ok";
|
||||
|
|
Loading…
Reference in a new issue