refactor: code flow and readability

This commit is contained in:
Lam Wei Li 2022-05-22 15:49:51 +08:00
parent 505204addc
commit 6de1da298e
No known key found for this signature in database
GPG Key ID: 90F6ABECF080D7BF

View File

@ -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 {