1
0
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:
Matt Gibson 2021-03-02 11:25:45 -06:00 committed by GitHub
parent 3942868cf4
commit 36089fd68f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {