From 49b07d1a841728060d2ee4389309cd93f74888e8 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Sat, 17 Sep 2016 09:03:11 -0400 Subject: [PATCH] Fix npm clean commands Auditors: @bridiver Fix #3912 Test Plan: - Make sure the release bundled app is still linked to the session-store-1 file under the brave userData dir. You can check by moving away your session-store-1 file and making sure it clears your app data. - Run npm run clean-session-store and make sure the session-store-1 file under the brave-development folder gets removed --- app/browser/lib/patchUserDataDir.js | 15 +++++++++++++++ app/index.js | 9 +-------- package.json | 2 +- tools/clean.js | 2 +- tools/lib/utilApp/index.js | 7 ++++--- 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 app/browser/lib/patchUserDataDir.js diff --git a/app/browser/lib/patchUserDataDir.js b/app/browser/lib/patchUserDataDir.js new file mode 100644 index 00000000000..310ff3cb572 --- /dev/null +++ b/app/browser/lib/patchUserDataDir.js @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const path = require('path') +const {app} = require('electron') + +if (!process.env.BRAVE_USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) { + process.env.BRAVE_USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV) +} + +if (process.env.BRAVE_USER_DATA_DIR) { + app.setPath('userData', process.env.BRAVE_USER_DATA_DIR) +} + diff --git a/app/index.js b/app/index.js index d8053bea7c6..52e733a2d0d 100644 --- a/app/index.js +++ b/app/index.js @@ -24,17 +24,10 @@ if (process.platform === 'win32') { require('./windowsInit') } -const path = require('path') const electron = require('electron') const app = electron.app // set userData before loading anything else -if (!process.env.BRAVE_USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) { - process.env.BRAVE_USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV) -} - -if (process.env.BRAVE_USER_DATA_DIR) { - app.setPath('userData', process.env.BRAVE_USER_DATA_DIR) -} +require('./browser/lib/patchUserDataDir') const BrowserWindow = electron.BrowserWindow const dialog = electron.dialog const ipcMain = electron.ipcMain diff --git a/package.json b/package.json index 08d576f7795..a004ee96ffb 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "clean-adblock-data": "node ./tools/clean.js userData ABPFilterParserData.dat", "clean-httpse-data": "node ./tools/clean.js userData httpse.json", "clean-sb-data": "node ./tools/clean.js userData SafeBrowsingData.dat", - "clean-session-store": "node ./tools/clean.js userData session-store-1-dev", + "clean-session-store": "node ./tools/clean.js userData session-store-1", "clean-tp-data": "node ./tools/clean.js userData TrackingProtection.dat", "docs": "jsdox js/actions/appActions.js js/actions/windowActions.js --output docs", "download-languages": "node ./tools/downloadLanguages", diff --git a/tools/clean.js b/tools/clean.js index 0bf49eb1bd4..4dd07ac387f 100644 --- a/tools/clean.js +++ b/tools/clean.js @@ -40,7 +40,7 @@ module.exports.userData = (file = process.argv[3]) => { } module.exports.sessionStore = () => { - module.exports.userData('session-store-1-dev') + module.exports.userData('session-store-1') } module.exports.dataFiles = () => { diff --git a/tools/lib/utilApp/index.js b/tools/lib/utilApp/index.js index 9cae4525ea5..15a219211f2 100644 --- a/tools/lib/utilApp/index.js +++ b/tools/lib/utilApp/index.js @@ -1,11 +1,12 @@ 'use strict' -const path = require('path') -const rimraf = require('../rimraf') const electron = require('electron') const app = electron.app app.setName('brave') -app.setPath('userData', path.join(app.getPath('appData'), app.getName())) +require('../../../app/browser/lib/patchUserDataDir') + +const path = require('path') +const rimraf = require('../rimraf') const cleanUserData = (location) => { location = location ? path.join(app.getPath('userData'), location) : app.getPath('userData')