()
| 541 | * The regular cleanupOldVersions() should still be used for installer flows. |
| 542 | */ |
| 543 | export async function cleanupOldVersionsThrottled(): Promise<void> { |
| 544 | const markerPath = join(getClaudeConfigHomeDir(), '.version-cleanup') |
| 545 | |
| 546 | try { |
| 547 | const stat = await fs.stat(markerPath) |
| 548 | if (Date.now() - stat.mtimeMs < ONE_DAY_MS) { |
| 549 | logForDebugging('version cleanup: skipping, ran recently') |
| 550 | return |
| 551 | } |
| 552 | } catch { |
| 553 | // File doesn't exist, proceed with cleanup |
| 554 | } |
| 555 | |
| 556 | try { |
| 557 | await lockfile.lock(markerPath, { retries: 0, realpath: false }) |
| 558 | } catch { |
| 559 | logForDebugging('version cleanup: skipping, lock held') |
| 560 | return |
| 561 | } |
| 562 | |
| 563 | logForDebugging('version cleanup: starting (throttled)') |
| 564 | |
| 565 | try { |
| 566 | await cleanupOldVersions() |
| 567 | await fs.writeFile(markerPath, new Date().toISOString()) |
| 568 | } catch (error) { |
| 569 | logError(error as Error) |
| 570 | } finally { |
| 571 | await lockfile.unlock(markerPath, { realpath: false }).catch(() => {}) |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | export async function cleanupOldMessageFilesInBackground(): Promise<void> { |
| 576 | // If settings have validation errors but the user explicitly set cleanupPeriodDays, |
no test coverage detected