fix(library): a scan cut off by a restart no longer blocks saving library folders

A restart mid-scan left its scan_runs row unfinished, and saving library
folders refused ("A library scan is running") until a later scan reaped it,
up to 12 hours on. Startup now closes such rows with the reason before the
boot scan, as backups already do. Saving folders and the duplicate sweep
share one check that treats a run past StuckScanThreshold as dead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 22:02:00 -05:00
co-authored by Claude Opus 5.5
parent 1ff4bc8258
commit 785b15ab5f
7 changed files with 123 additions and 10 deletions
+4 -4
View File
@@ -598,15 +598,15 @@ func (w *DuplicateResolveWorker) tickOnce(ctx context.Context) (waitForScan bool
// A scan in flight has listed the files it will reconcile: a copy removed
// now is marked present again when it does. A run past StuckScanThreshold
// is a dead one.
run, err := q.GetInFlightScanRun(ctx)
running, err := scanRunning(ctx, q)
switch {
case err == nil && time.Since(run.StartedAt.Time) <= StuckScanThreshold:
return true
case err != nil && !errors.Is(err, pgx.ErrNoRows):
case err != nil:
if ctx.Err() == nil {
w.logger.Warn("duplicate resolve: scan check failed", "err", err)
}
return false
case running:
return true
}
res, err := ResolveDuplicatesWith(ctx, w.pool, w.logger, w.dataDir, w.settings.Get().AutoResolve, w.src)
if err != nil && ctx.Err() == nil {