From 01392b1c995dfc23c8845db7758255c9a7b6b1d1 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 27 Oct 2021 16:31:16 +1100 Subject: [PATCH] make sure the log folder exists before fetching it Relates #1982 --- app/logging.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/logging.js b/app/logging.js index 720c187b6..0022d6650 100644 --- a/app/logging.js +++ b/app/logging.js @@ -21,11 +21,6 @@ let logger; module.exports = { initialize, getLogger, - // for tests only: - isLineAfterDate, - eliminateOutOfDateFiles, - eliminateOldEntries, - fetchLog, fetch, }; @@ -64,6 +59,8 @@ function initialize() { }); ipc.on('fetch-log', event => { + mkdirp.sync(logPath); + fetch(logPath).then( data => { event.sender.send('fetched-log', data); @@ -107,7 +104,7 @@ async function deleteAllLogs(logPath) { async function cleanupLogs(logPath) { const now = new Date(); const earliestDate = new Date( - Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 3) + Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 6) ); try { @@ -217,6 +214,11 @@ function fetchLog(logFile) { } function fetch(logPath) { + // Check that the file exists locally + if (!fs.existsSync(logPath)) { + console._log('Log folder not found while fetching its content. Quick! Creating it.'); + mkdirp.sync(logPath); + } const files = fs.readdirSync(logPath); const paths = files.map(file => path.join(logPath, file));