From 6de1da298e7745fe036a523181a278d0ad66184a Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sun, 22 May 2022 15:49:51 +0800 Subject: [PATCH] refactor: code flow and readability --- lib/appenders/fileSync.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/appenders/fileSync.js b/lib/appenders/fileSync.js index 763da33..7519de5 100755 --- a/lib/appenders/fileSync.js +++ b/lib/appenders/fileSync.js @@ -6,11 +6,6 @@ const os = require('os'); const eol = os.EOL; function touchFile(file, options) { - // if the file exists, nothing to do - if (fs.existsSync(file)) { - return; - } - // attempt to create the directory const mkdir = (dir) => { try { @@ -45,9 +40,8 @@ function touchFile(file, options) { }; mkdir(path.dirname(file)); - // touch the file to apply flags (like w to truncate the file) - const id = fs.openSync(file, options.flags, options.mode); - fs.closeSync(id); + // try to throw EISDIR, EROFS, EACCES + fs.appendFileSync(file, "", { mode: options.mode, flags: options.flag }); } class RollingFileSync {