From 9c889c7cffc132beef4d3a036d2e0769ed911e05 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 12 Apr 2017 20:38:50 -0700 Subject: [PATCH] [client-app] Prevent old N1 config from getting wiped when installing Nylas Mail Summary: Due to a legacy migration system, users that had previously installed old N1 (1.5.0) would get their N1 config wiped after installing Nylas Mail (2.0) in most cases. See https://github.com/nylas/nylas-mail/blob/n1-pro/src/browser/nylas-pro-migrator.es6 for details Fixes T8096 Test Plan: manual Reviewers: halla, spang, mark Reviewed By: mark Maniphest Tasks: T8096 Differential Revision: https://phab.nylas.com/D4417 --- .../client-app/src/browser/application.es6 | 3 +++ .../browser/prevent-legacy-n1-migration.es6 | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 packages/client-app/src/browser/prevent-legacy-n1-migration.es6 diff --git a/packages/client-app/src/browser/application.es6 b/packages/client-app/src/browser/application.es6 index b51966031..ed20ae956 100644 --- a/packages/client-app/src/browser/application.es6 +++ b/packages/client-app/src/browser/application.es6 @@ -21,6 +21,7 @@ import DefaultClientHelper from '../default-client-helper'; import NylasProtocolHandler from './nylas-protocol-handler'; import PackageMigrationManager from './package-migration-manager'; import ConfigPersistenceManager from './config-persistence-manager'; +import preventLegacyN1Migration from './prevent-legacy-n1-migration'; let clipboard = null; @@ -55,6 +56,8 @@ export default class Application extends EventEmitter { this.configPersistenceManager = new ConfigPersistenceManager({configDirPath, resourcePath}); config.load(); + preventLegacyN1Migration(configDirPath) + this.configMigrator = new ConfigMigrator(this.config, this.databaseReader); this.configMigrator.migrate() diff --git a/packages/client-app/src/browser/prevent-legacy-n1-migration.es6 b/packages/client-app/src/browser/prevent-legacy-n1-migration.es6 new file mode 100644 index 000000000..ca4a0060f --- /dev/null +++ b/packages/client-app/src/browser/prevent-legacy-n1-migration.es6 @@ -0,0 +1,22 @@ +import fs from 'fs' +import path from 'path' + +// This function prevents old N1 from destroying its own config and copying the +// one from Nylas Mail 2.0. The expected workflow now is to migrate from old +// N1 (1.5.0) to Nylas Mail (2.0) instead of the other way around +// See https://github.com/nylas/nylas-mail/blob/n1-pro/src/browser/nylas-pro-migrator.es6 for details +export default function preventLegacyN1Migration(configDirPath) { + try { + const legacyConfigPath = path.join(configDirPath, '..', '.nylas', 'config.json') + if (!fs.existsSync(legacyConfigPath)) { return } + const legacyConfig = require(legacyConfigPath) || {} // eslint-disable-line + if (!legacyConfig['*']) { + legacyConfig['*'] = {} + } + legacyConfig['*'].nylasMailBasicMigrationTime = Date.now() + fs.writeFileSync(legacyConfigPath, JSON.stringify(legacyConfig)) + } catch (err) { + console.error('Error preventing legacy N1 migration') + console.error(err) + } +}