Skip to content

Commit

Permalink
[core] Fix delete file when it doesn't exist anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
allburov committed Feb 18, 2024
1 parent b4fb69d commit 0b03abe
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/storage/LocalSessionConfigRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ export class LocalSessionConfigRepository extends ISessionConfigRepository {
this.store = store;
}

async get(sessionName: string): Promise<SessionConfig | null> {
const filepath = this.getFilePath(sessionName);
// Check file exists
private async fileExists(filepath: string) {
try {
await fs.access(filepath, fs.constants.F_OK);
} catch (error) {
return false;
}
return true;
}

async get(sessionName: string): Promise<SessionConfig | null> {
const filepath = this.getFilePath(sessionName);
// Check file exists
if (!(await this.fileExists(filepath))) {
return null;
}

Expand Down Expand Up @@ -51,6 +58,9 @@ export class LocalSessionConfigRepository extends ISessionConfigRepository {

async delete(sessionName: string): Promise<void> {
const filepath = this.getFilePath(sessionName);
if (!(await this.fileExists(filepath))) {
return;
}
await fs.unlink(filepath);
}
}

0 comments on commit 0b03abe

Please sign in to comment.