Skip to content

Commit 674fe70

Browse files
committed
refactor: adjust dir creation
1 parent f32147d commit 674fe70

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/utils/src/lib/wal-sharded.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ export class ShardedWal<T extends WalRecord = WalRecord> {
329329
}
330330

331331
const groupDir = path.join(this.#dir, this.groupId);
332-
// create dir if not existing
333-
ensureDirectoryExistsSync(groupDir);
332+
if (!fs.existsSync(groupDir)) {
333+
return [];
334+
}
334335

335336
return fs
336337
.readdirSync(groupDir)
@@ -358,18 +359,18 @@ export class ShardedWal<T extends WalRecord = WalRecord> {
358359
// Ensure base directory exists before calling shardFiles()
359360
ensureDirectoryExistsSync(this.#dir);
360361

361-
const fileRecoveries = this.shardFiles().map(f => ({
362+
const lastRecovery = this.shardFiles().map(f => ({
362363
file: f,
363364
result: new WriteAheadLogFile({
364365
file: f,
365366
codec: this.#format.codec,
366367
}).recover(),
367368
}));
368369

369-
const records = fileRecoveries.flatMap(({ result }) => result.records);
370+
const records = lastRecovery.flatMap(({ result }) => result.records);
370371

371372
if (this.#debug) {
372-
this.#lastRecovery = fileRecoveries;
373+
this.#lastRecovery = lastRecovery;
373374
}
374375

375376
ensureDirectoryExistsSync(path.dirname(this.getFinalFilePath()));

0 commit comments

Comments
 (0)