mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Fix logic in saveAsBackup
This commit is contained in:
parent
5e375b61c3
commit
5224bc5c41
1 changed files with 3 additions and 8 deletions
|
|
@ -23,17 +23,12 @@ const _write = (path: string, data: string) => {
|
|||
const saveAsBackup = (src: string) => {
|
||||
let attempt = 1;
|
||||
while (attempt < 100) {
|
||||
try {
|
||||
const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`;
|
||||
const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`;
|
||||
if (!existsSync(backupPath)) {
|
||||
moveSync(src, backupPath);
|
||||
return backupPath;
|
||||
} catch (e) {
|
||||
if (e.code === 'EEXIST') {
|
||||
attempt++;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
attempt++;
|
||||
}
|
||||
throw new Error('Failed to create backup for config file. Too many backups');
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue