Skip to content

Commit

Permalink
fix: Race condition which causes upgrade assistant to write new confi…
Browse files Browse the repository at this point in the history
…g to backup file.
  • Loading branch information
about-code committed Dec 22, 2020
1 parent d4c8646 commit f419aa7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/cli/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {copy, writeFile} = require("fs-extra");
const {copySync, writeFile} = require("fs-extra");
const inquirer = require("inquirer");

const upgrades = [v4To5];
Expand Down Expand Up @@ -90,10 +90,12 @@ function upgrade(confData, confFile, defaultConf) {
return new Promise((resolve, reject) => {
if (answers.keepBackup) {
const backupFile = confFile + ".old";
copy(confFile, backupFile, (err) => {
if (err) { reject(err); }
try {
copySync(confFile, backupFile);
console.info(`Backup of previous configuration in '${backupFile}'`);
});
} catch (err) {
reject(err);
};
}
const newConf = performUpgrades(confData, effectiveVersion);
if (hasUpgradePath(newConf, effectiveVersion)) {
Expand Down

0 comments on commit f419aa7

Please sign in to comment.