From b8d6cb399cc10a54da16acf501a24269e72de3cd Mon Sep 17 00:00:00 2001 From: C-D-Lewis Date: Wed, 23 Oct 2024 21:53:43 +0100 Subject: [PATCH] Fix unlink --- node-common/src/modules/log.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/node-common/src/modules/log.js b/node-common/src/modules/log.js index bb60ce2..9b677fc 100644 --- a/node-common/src/modules/log.js +++ b/node-common/src/modules/log.js @@ -177,8 +177,12 @@ const getLogfileSizeMb = () => { * Monitor the log size, and erase if it gets too big. */ const monitorLogSize = () => { - // Initally clear - fs.unlinkSync(getFilePath()); + const filePath = getFilePath(); + + if (fs.existsSync(filePath)) { + // Initally clear + fs.unlinkSync(getFilePath()); + } setInterval(() => { const sizeMb = getLogfileSizeMb(); @@ -187,7 +191,7 @@ const monitorLogSize = () => { if (sizeMb < MAX_SIZE_MB) return; // Erase the file and start again - fs.unlinkSync(getFilePath()); + fs.unlinkSync(filePath); info('Log file exceeded max size and was restarted'); }, MONITOR_INTERVAL_MS); info(`Monitoring logfile size (currently ${getLogfileSizeMb()} MB)`);