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:
parent
7941664a59
commit
fc1275aeb2
@ -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.');
|
||||||
|
Loading…
Reference in New Issue
Block a user