Skip to content

Commit

Permalink
Fix migrating persistant old identity file (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuki145 authored and djordjekovac committed Dec 26, 2019
1 parent 51908f3 commit bafb342
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
17 changes: 11 additions & 6 deletions modules/migration/m3-network-identity-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ class M3NetworkIdentityMigration {

const backupPath = path.join(this.config.appDataPath, 'Node_2_0_59_Identity_Backup');
const { xprivkey, index } = identityFileContent;
if ((xprivkey || index)
&& this.config.autoUpdater.enabled
&& !fs.existsSync(backupPath)) {
if ((xprivkey || index) && this.config.autoUpdater.enabled) {
this.logger.info('Old network identity detected, running code migrations...');

// Backup data
execSync(`mkdir ${backupPath}`);
if (!fs.existsSync(backupPath)) {
execSync(`mkdir ${backupPath}`);

try {
execSync(`/bin/mv ${path.join(this.config.appDataPath, 'peercache')} ${backupPath}/`);
execSync(`/bin/mv ${path.join(this.config.appDataPath, 'kadence.dht')} ${backupPath}/`);
} catch (e) {
this.logger.debug('peercache and kadence.dht not found');
}
}

execSync(`/bin/mv ${identityFilePath} ${backupPath}/`);
execSync(`/bin/mv ${path.join(this.config.appDataPath, 'peercache')} ${backupPath}/`);
execSync(`/bin/mv ${path.join(this.config.appDataPath, 'kadence.dht')} ${backupPath}/`);
}
}
}
Expand Down
24 changes: 8 additions & 16 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,22 +498,14 @@ class OTNode {
async _runNetworkIdentityMigration(config) {
const migrationsStartedMills = Date.now();

const migrationDir = path.join(config.appDataPath, 'migrations');
const m3NetworkIdentityMigrationFilename = '3_m3NetworkIdentityMigrationFile';
const migrationFilePath = path.join(migrationDir, m3NetworkIdentityMigrationFilename);
if (!fs.existsSync(migrationFilePath)) {
const migration = new M3NetowrkIdentityMigration({ logger: log, config });
try {
await migration.run();
log.notify(`One-time network identity migration completed. Lasted ${Date.now() - migrationsStartedMills} millisecond(s)`);

await Utilities.writeContentsToFile(migrationDir, m3NetworkIdentityMigrationFilename, 'PROCESSED');
} catch (e) {
log.error(`Failed to run code migrations. Lasted ${Date.now() - migrationsStartedMills} millisecond(s). ${e.message}`);
console.log(e);
notifyBugsnag(e);
process.exit(1);
}
const migration = new M3NetowrkIdentityMigration({ logger: log, config });
try {
await migration.run();
} catch (e) {
log.error(`Failed to run code migrations. Lasted ${Date.now() - migrationsStartedMills} millisecond(s). ${e.message}`);
console.log(e);
notifyBugsnag(e);
process.exit(1);
}
}

Expand Down

0 comments on commit bafb342

Please sign in to comment.