[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
This commit is contained in:
Juan Tejada 2017-04-12 20:38:50 -07:00
parent 664da98c22
commit 9c889c7cff
2 changed files with 25 additions and 0 deletions

View file

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

View file

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