mirror of
https://github.com/bitwarden/browser
synced 2025-01-20 16:31:15 +01:00
Write backup before deleting lowdb database (#291)
* Write backup before deleting lowdb database * Const for unchanged variables
This commit is contained in:
parent
3942868cf4
commit
36089fd68f
@ -47,6 +47,13 @@ export class LowdbStorageService implements StorageService {
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
this.logService.warning(`Error creating lowdb storage adapter, "${e.message}"; emptying data file.`);
|
||||
if (fs.existsSync(this.dataFilePath)) {
|
||||
const backupPath = this.dataFilePath + '.bak';
|
||||
this.logService.warning(`Writing backup of data file to ${backupPath}`);
|
||||
await fs.copyFile(this.dataFilePath, backupPath, err => {
|
||||
this.logService.warning(`Error while creating data file backup, "${e.message}". No backup may have been created.`);
|
||||
});
|
||||
}
|
||||
adapter.write({});
|
||||
this.db = lowdb(adapter);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user