mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Write backup before deleting lowdb database (#291)
* Write backup before deleting lowdb database * Const for unchanged variables
This commit is contained in:
@@ -47,6 +47,13 @@ export class LowdbStorageService implements StorageService {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof SyntaxError) {
|
if (e instanceof SyntaxError) {
|
||||||
this.logService.warning(`Error creating lowdb storage adapter, "${e.message}"; emptying data file.`);
|
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({});
|
adapter.write({});
|
||||||
this.db = lowdb(adapter);
|
this.db = lowdb(adapter);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user