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
+5 -5
View File
@@ -80,13 +80,13 @@ func (s *Scanner) SetRoots(ctx context.Context, changes []RootChange) (RerootRes
q := dbq.New(s.pool)
// A scan walking the old folders would put their paths back, or mark the
// moved rows missing when it reconciles.
_, err = q.GetInFlightScanRun(ctx)
if err == nil {
return RerootResult{}, badRoots("A library scan is running; save again once it finishes.")
}
if !errors.Is(err, pgx.ErrNoRows) {
running, err := scanRunning(ctx, q)
if err != nil {
return RerootResult{}, fmt.Errorf("in-flight scan check: %w", err)
}
if running {
return RerootResult{}, badRoots("A library scan is running; save again once it finishes.")
}
for _, m := range moves {
if err := checkMove(ctx, q, m); err != nil {
return RerootResult{}, err