sonda/cmd/sondad/scan.go
tgiachi a880b87a9e chore: move the module path to git.kmalloc.org/squid/sonda
Migrating hosting from Codeberg to git.kmalloc.org. Renames the
module path in go.mod, every internal import, and the OCI image
source label in the Dockerfile. Build and full test suite verified
green after the rename.
2026-11-15 17:30:29 +01:00

63 lines
2 KiB
Go

package main
import (
"context"
"go.uber.org/zap"
"git.kmalloc.org/squid/sonda/internal/library"
)
// scanControl lets the HTTP layer start scans that live as long as the
// application, not as long as a single request.
type scanControl struct {
ctx context.Context
m *library.Manager
}
func (c scanControl) Start(full bool) error { return c.m.Start(c.ctx, scanOptions(full)...) }
func (c scanControl) StartLibrary(id int64, full bool) error {
return c.m.StartLibrary(c.ctx, id, scanOptions(full)...)
}
func (c scanControl) Status() library.Status { return c.m.Status() }
func scanOptions(full bool) []library.ScanOption {
if full {
return []library.ScanOption{library.FullRescan}
}
return nil
}
// logScanResults writes one log line per finished scan. File paths are left
// out on purpose: audio paths are private.
func logScanResults(logger *zap.Logger, m *library.Manager) {
m.OnFinish(func(s library.Summary, err error) {
fields := []zap.Field{
zap.Int("found", s.Found), zap.Int("added", s.Added), zap.Int("updated", s.Updated),
zap.Int("unchanged", s.Unchanged), zap.Int("renamed", s.Renamed),
zap.Int("restored", s.Restored), zap.Int("missing", s.Missing),
zap.Int("failed", s.Failed), zap.Int("skipped", s.Skipped),
}
if err != nil {
logger.Warn("library scan finished with errors", append(fields, zap.Error(err))...)
return
}
logger.Info("library scan finished", fields...)
})
}
// warnAboutLibraries logs libraries that look wrong. Rows created by the
// upgrade from the roots-in-config versions skip validation, so a stale root
// can show up as a missing directory or as a library inside another one.
func warnAboutLibraries(ctx context.Context, logger *zap.Logger, libs *library.Libraries) {
problems, err := libs.Problems(ctx)
if err != nil {
logger.Warn("could not check the libraries", zap.Error(err))
return
}
for _, p := range problems {
logger.Warn("library problem: review GET /api/v1/libraries", zap.String("problem", p))
}
}