1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-13 10:24:20 +01:00

Do not lock until after the file is created (#274)

Proper-lockfile throws if the file it's locking does not exist.
Lock around adapter creation rather than file creation.
This commit is contained in:
Matt Gibson 2021-02-16 22:29:57 -06:00 committed by GitHub
parent 7941664a59
commit fc1275aeb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,7 +28,6 @@ export class LowdbStorageService implements StorageService {
this.logService.info(`Created dir "${this.dir}".`); this.logService.info(`Created dir "${this.dir}".`);
} }
this.dataFilePath = path.join(this.dir, 'data.json'); this.dataFilePath = path.join(this.dir, 'data.json');
await this.lockDbFile(() => {
if (!fs.existsSync(this.dataFilePath)) { if (!fs.existsSync(this.dataFilePath)) {
this.logService.warning(`Could not find data file, "${this.dataFilePath}"; creating it instead.`); this.logService.warning(`Could not find data file, "${this.dataFilePath}"; creating it instead.`);
fs.writeFileSync(this.dataFilePath, '', { mode: 0o600 }); fs.writeFileSync(this.dataFilePath, '', { mode: 0o600 });
@ -37,8 +36,9 @@ export class LowdbStorageService implements StorageService {
} else { } else {
this.logService.info(`db file "${this.dataFilePath} already exists"; using existing db`); this.logService.info(`db file "${this.dataFilePath} already exists"; using existing db`);
} }
}); await this.lockDbFile(() => {
adapter = new FileSync(this.dataFilePath); adapter = new FileSync(this.dataFilePath);
});
} }
try { try {
this.logService.info('Attempting to create lowdb storage adapter.'); this.logService.info('Attempting to create lowdb storage adapter.');