ImportHandler: Avoid deprecated `fs.exists()` function

pull/4779/head
Richard Hansen 2021-02-07 18:35:00 -05:00 committed by John McLear
parent 008209b0e0
commit c7b1abebe4
1 changed files with 10 additions and 14 deletions

View File

@ -34,11 +34,18 @@ const log4js = require('log4js');
const hooks = require('../../static/js/pluginfw/hooks.js');
const util = require('util');
const fsp_exists = util.promisify(fs.exists);
const fsp_rename = util.promisify(fs.rename);
const fsp_readFile = util.promisify(fs.readFile);
const fsp_unlink = util.promisify(fs.unlink);
const rm = async (path) => {
try {
await fsp_unlink(path);
} catch (err) {
if (err.code !== 'ENOENT') throw err;
}
};
let convertor = null;
let exportExtension = 'htm';
@ -239,19 +246,8 @@ const doImport = async (req, res, padId) => {
await padMessageHandler.updatePadClients(pad);
// clean up temporary files
/*
* TODO: directly delete the file and handle the eventual error. Checking
* before for existence is prone to race conditions, and does not handle any
* errors anyway.
*/
if (await fsp_exists(srcFile)) {
fsp_unlink(srcFile);
}
if (await fsp_exists(destFile)) {
fsp_unlink(destFile);
}
rm(srcFile);
rm(destFile);
};
exports.doImport = (req, res, padId) => {