make sure the log folder exists before fetching it

Relates #1982
pull/1991/head
Audric Ackermann 3 years ago
parent 5b57e01186
commit 01392b1c99
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -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));

Loading…
Cancel
Save