mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
refactor(scanner): enhance ScanTarget struct with String method for better target representation
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
b06d90a4db
commit
f64b51f161
@ -27,11 +27,16 @@ var (
|
||||
)
|
||||
|
||||
// ScanTarget represents a specific folder within a library to be scanned.
|
||||
// NOTE: This struct is used as a map key, so it should only contain comparable types.
|
||||
type ScanTarget struct {
|
||||
LibraryID int
|
||||
FolderPath string // Relative path within the library, or "" for entire library
|
||||
}
|
||||
|
||||
func (st ScanTarget) String() string {
|
||||
return fmt.Sprintf("%d:%s", st.LibraryID, st.FolderPath)
|
||||
}
|
||||
|
||||
type Scanner interface {
|
||||
// ScanAll starts a full scan of the music library. This is a blocking operation.
|
||||
ScanAll(ctx context.Context, fullScan bool) (warnings []string, err error)
|
||||
|
||||
@ -8,10 +8,11 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/utils/slice"
|
||||
)
|
||||
|
||||
// scannerExternal is a scanner that runs an external process to do the scanning. It is used to avoid
|
||||
@ -49,13 +50,7 @@ func (s *scannerExternal) scan(ctx context.Context, fullScan bool, targets []Sca
|
||||
|
||||
// Add targets if provided
|
||||
if len(targets) > 0 {
|
||||
var targetsStr string
|
||||
for i, target := range targets {
|
||||
if i > 0 {
|
||||
targetsStr += ","
|
||||
}
|
||||
targetsStr += strconv.Itoa(target.LibraryID) + ":" + target.FolderPath
|
||||
}
|
||||
targetsStr := strings.Join(slice.Map(targets, func(t ScanTarget) string { return t.String() }), ",")
|
||||
args = append(args, "--targets", targetsStr)
|
||||
log.Debug(ctx, "Spawning external scanner process with targets", "fullScan", fullScan, "path", exe, "targets", targetsStr)
|
||||
} else {
|
||||
|
||||
@ -121,10 +121,11 @@ func (w *watcher) Run(ctx context.Context) error {
|
||||
folderPath := notification.FolderPath
|
||||
|
||||
// If already scheduled for scan, skip
|
||||
if _, exists := targets[ScanTarget{LibraryID: lib.ID, FolderPath: folderPath}]; exists {
|
||||
target := ScanTarget{LibraryID: lib.ID, FolderPath: folderPath}
|
||||
if _, exists := targets[target]; exists {
|
||||
continue
|
||||
}
|
||||
targets[ScanTarget{LibraryID: lib.ID, FolderPath: folderPath}] = struct{}{}
|
||||
targets[target] = struct{}{}
|
||||
trigger.Reset(w.triggerWait)
|
||||
|
||||
log.Debug(ctx, "Watcher: Detected changes. Waiting for more changes before triggering scan",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user