(tag: string)
| 357 | } |
| 358 | |
| 359 | async deleteCheckpoint(tag: string): Promise<boolean> { |
| 360 | if (!this.initialized || !this.anusDir) { |
| 361 | console.error( |
| 362 | 'Logger not initialized or checkpoint file path not set. Cannot delete checkpoint.', |
| 363 | ); |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | let deletedSomething = false; |
| 368 | |
| 369 | // 1. Attempt to delete the new encoded path. |
| 370 | const newPath = this._checkpointPath(tag); |
| 371 | try { |
| 372 | await fs.unlink(newPath); |
| 373 | deletedSomething = true; |
| 374 | } catch (error) { |
| 375 | const nodeError = error as NodeJS.ErrnoException; |
| 376 | if (nodeError.code !== 'ENOENT') { |
| 377 | console.error(`Failed to delete checkpoint file ${newPath}:`, error); |
| 378 | throw error; // Rethrow unexpected errors |
| 379 | } |
| 380 | // It's okay if it doesn't exist. |
| 381 | } |
| 382 | |
| 383 | // 2. Attempt to delete the old raw path for backward compatibility. |
| 384 | const oldPath = path.join(this.anusDir!, `checkpoint-${tag}.json`); |
| 385 | if (newPath !== oldPath) { |
| 386 | try { |
| 387 | await fs.unlink(oldPath); |
| 388 | deletedSomething = true; |
| 389 | } catch (error) { |
| 390 | const nodeError = error as NodeJS.ErrnoException; |
| 391 | if (nodeError.code !== 'ENOENT') { |
| 392 | console.error(`Failed to delete checkpoint file ${oldPath}:`, error); |
| 393 | throw error; // Rethrow unexpected errors |
| 394 | } |
| 395 | // It's okay if it doesn't exist. |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | return deletedSomething; |
| 400 | } |
| 401 | |
| 402 | async checkpointExists(tag: string): Promise<boolean> { |
| 403 | if (!this.initialized) { |
no test coverage detected