mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-17 14:08: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) => {
|
const saveAsBackup = (src: string) => {
|
||||||
let attempt = 1;
|
let attempt = 1;
|
||||||
while (attempt < 100) {
|
while (attempt < 100) {
|
||||||
try {
|
const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`;
|
||||||
const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`;
|
if (!existsSync(backupPath)) {
|
||||||
moveSync(src, backupPath);
|
moveSync(src, backupPath);
|
||||||
return 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');
|
throw new Error('Failed to create backup for config file. Too many backups');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue