From 59a6f2e9b8adedf1892e0ec8b763cac57b4af53b Mon Sep 17 00:00:00 2001 From: muxator Date: Tue, 19 Feb 2019 00:48:50 +0100 Subject: [PATCH] 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 --- src/node/handler/ImportHandler.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index b08bdcf60..30b773972 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -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";