Skip to content

Commit 0b03abe

Browse files
author
allburov
committed
[core] Fix delete file when it doesn't exist anymore
1 parent b4fb69d commit 0b03abe

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/core/storage/LocalSessionConfigRepository.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ export class LocalSessionConfigRepository extends ISessionConfigRepository {
1414
this.store = store;
1515
}
1616

17-
async get(sessionName: string): Promise<SessionConfig | null> {
18-
const filepath = this.getFilePath(sessionName);
19-
// Check file exists
17+
private async fileExists(filepath: string) {
2018
try {
2119
await fs.access(filepath, fs.constants.F_OK);
2220
} catch (error) {
21+
return false;
22+
}
23+
return true;
24+
}
25+
26+
async get(sessionName: string): Promise<SessionConfig | null> {
27+
const filepath = this.getFilePath(sessionName);
28+
// Check file exists
29+
if (!(await this.fileExists(filepath))) {
2330
return null;
2431
}
2532

@@ -51,6 +58,9 @@ export class LocalSessionConfigRepository extends ISessionConfigRepository {
5158

5259
async delete(sessionName: string): Promise<void> {
5360
const filepath = this.getFilePath(sessionName);
61+
if (!(await this.fileExists(filepath))) {
62+
return;
63+
}
5464
await fs.unlink(filepath);
5565
}
5666
}

0 commit comments

Comments
 (0)