fix(library): a file back at a waiting track's path brings it back at once
release / go (push) Successful in 1m40s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m50s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m45s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 42s
release / Verify release artifacts (tag releases only) (push) Skipped

The watcher scans single files and never reconciles, and a file restored
with its old mtime takes the unchanged skip, so a track whose file came
back at the same path waited in Needs a file for the next full scan. The
scan now clears the mark when the path it reads belongs to a waiting
track, and tells clients it plays again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 13:05:48 -05:00
co-authored by Claude Opus 5.5
parent 813c289bc0
commit 71a1a7414a
2 changed files with 91 additions and 1 deletions
+28 -1
View File
@@ -257,6 +257,22 @@ func (s *Scanner) enumerate(
return paths, errs
}
// clearReturned takes the missing mark (and any removal reason) off a track
// whose file is back at its path, and tells clients it plays again. Counted
// as Restored, like the reconcile pass's clears.
func (s *Scanner) clearReturned(ctx context.Context, q *dbq.Queries, id pgtype.UUID, stats *Stats) error {
ids := []pgtype.UUID{id}
if err := logTrackChanges(ctx, q, ids); err != nil {
return fmt.Errorf("log returned change: %w", err)
}
n, err := q.ClearTracksMissing(ctx, ids)
if err != nil {
return fmt.Errorf("clear missing mark: %w", err)
}
stats.Restored += int(n)
return nil
}
// scanFile upserts a single audio file. Returns the album ID the track
// belongs to and whether the file was added/updated (false = skipped as
// unchanged), so watcher-driven callers can enrich just the changed albums.
@@ -276,6 +292,16 @@ func (s *Scanner) scanFile(
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
return pgtype.UUID{}, false, fmt.Errorf("lookup: %w", err)
}
// A file at the path of a track waiting for one is that track's file
// back. The full scan's reconcile clears these too, but the watcher scans
// single files and never reconciles, and a file restored with its old
// mtime takes the skip below, so without this the track would wait for the
// next full scan.
if knownTrack && existing.MissingSince.Valid {
if err := s.clearReturned(ctx, q, existing.ID, stats); err != nil {
return pgtype.UUID{}, false, err
}
}
// Incremental skip: only when the file hasn't changed AND we already have a
// real duration AND the row's tag-derived columns were written by the
// current extraction logic. The duration clause backfills rows that
@@ -497,10 +523,11 @@ func (s *Scanner) ScanFiles(ctx context.Context, paths []string) ([]pgtype.UUID,
}
}
}
if stats.Added > 0 || stats.Updated > 0 {
if stats.Added > 0 || stats.Updated > 0 || stats.Restored > 0 {
s.logger.Info("library watch: scan batch",
"added", stats.Added,
"updated", stats.Updated,
"restored", stats.Restored,
"skipped", stats.Skipped,
"errored", stats.Errored,
)