From afd9e464f21b0b6ba1896271d72ca0d5675d2b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 31 Jul 2018 13:54:11 +0200 Subject: [PATCH] Fixes #1337 --- src/components/SettingsPage/sections/Help.js | 2 +- src/helpers/log.js | 17 +++++++++++++++++ src/helpers/resolveLogsDirectory.js | 12 ------------ src/logger/logger.js | 2 +- src/main/bridge.js | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 src/helpers/log.js delete mode 100644 src/helpers/resolveLogsDirectory.js diff --git a/src/components/SettingsPage/sections/Help.js b/src/components/SettingsPage/sections/Help.js index ac2ae1b1..fdc71fbe 100644 --- a/src/components/SettingsPage/sections/Help.js +++ b/src/components/SettingsPage/sections/Help.js @@ -5,7 +5,7 @@ import { translate } from 'react-i18next' import type { T } from 'types/common' import TrackPage from 'analytics/TrackPage' import IconHelp from 'icons/Help' -import resolveLogsDirectory from 'helpers/resolveLogsDirectory' +import { resolveLogsDirectory } from 'helpers/log' import { urls } from 'config/urls' import ExportLogsBtn from 'components/ExportLogsBtn' diff --git a/src/helpers/log.js b/src/helpers/log.js new file mode 100644 index 00000000..c2ed8921 --- /dev/null +++ b/src/helpers/log.js @@ -0,0 +1,17 @@ +// @flow + +import path from 'path' +import rimraf from 'rimraf' +import resolveUserDataDirectory from './resolveUserDataDirectory' + +export const resolveLogsDirectory = () => { + const { LEDGER_LOGS_DIRECTORY } = process.env + if (LEDGER_LOGS_DIRECTORY) return LEDGER_LOGS_DIRECTORY + const electron = require('electron') + return path.resolve((electron.app || electron.remote.app).getPath('userData'), 'logs') +} + +export const cleanUpBeforeClosingSync = () => { + rimraf.sync(resolveLogsDirectory(), { disableGlob: true }) + rimraf.sync(path.resolve(resolveUserDataDirectory(), 'sqlite/*.log')) +} diff --git a/src/helpers/resolveLogsDirectory.js b/src/helpers/resolveLogsDirectory.js deleted file mode 100644 index cbfd8afa..00000000 --- a/src/helpers/resolveLogsDirectory.js +++ /dev/null @@ -1,12 +0,0 @@ -// @flow - -import path from 'path' - -const resolveLogsDirectory = () => { - const { LEDGER_LOGS_DIRECTORY } = process.env - if (LEDGER_LOGS_DIRECTORY) return LEDGER_LOGS_DIRECTORY - const electron = require('electron') - return path.resolve((electron.app || electron.remote.app).getPath('userData'), 'logs') -} - -export default resolveLogsDirectory diff --git a/src/logger/logger.js b/src/logger/logger.js index d6768c54..58eaf83b 100644 --- a/src/logger/logger.js +++ b/src/logger/logger.js @@ -2,7 +2,7 @@ import winston from 'winston' import Transport from 'winston-transport' -import resolveLogsDirectory from 'helpers/resolveLogsDirectory' +import { resolveLogsDirectory } from 'helpers/log' import anonymizer from 'helpers/anonymizer' import pname from 'helpers/pname' diff --git a/src/main/bridge.js b/src/main/bridge.js index eb26a90e..e302d559 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -9,7 +9,7 @@ import path from 'path' import logger from 'logger' import sentry, { captureException } from 'sentry/node' import user from 'helpers/user' -import resolveLogsDirectory from 'helpers/resolveLogsDirectory' +import { resolveLogsDirectory, cleanUpBeforeClosingSync } from 'helpers/log' import { deserializeError } from 'helpers/errors' import setupAutoUpdater, { quitAndInstall } from './autoUpdate' @@ -69,6 +69,7 @@ const bootInternalProcess = () => { process.on('exit', () => { killInternalProcess() + cleanUpBeforeClosingSync() }) ipcMain.on('clean-processes', () => {