fix(scanner): Use repeated arg instead of comma split (#4727)
This commit is contained in:
+4
-5
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
"github.com/navidrome/navidrome/db"
|
"github.com/navidrome/navidrome/db"
|
||||||
@@ -19,13 +18,13 @@ import (
|
|||||||
var (
|
var (
|
||||||
fullScan bool
|
fullScan bool
|
||||||
subprocess bool
|
subprocess bool
|
||||||
targets string
|
targets []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
scanCmd.Flags().BoolVarP(&fullScan, "full", "f", false, "check all subfolders, ignoring timestamps")
|
scanCmd.Flags().BoolVarP(&fullScan, "full", "f", false, "check all subfolders, ignoring timestamps")
|
||||||
scanCmd.Flags().BoolVarP(&subprocess, "subprocess", "", false, "run as subprocess (internal use)")
|
scanCmd.Flags().BoolVarP(&subprocess, "subprocess", "", false, "run as subprocess (internal use)")
|
||||||
scanCmd.Flags().StringVarP(&targets, "targets", "t", "", "comma-separated list of libraryID:folderPath pairs (e.g., \"1:Music/Rock,1:Music/Jazz,2:Classical\")")
|
scanCmd.Flags().StringArrayVarP(&targets, "target", "t", []string{}, "list of libraryID:folderPath pairs, can be repeated (e.g., \"-t 1:Music/Rock -t 1:Music/Jazz -t 2:Classical\")")
|
||||||
rootCmd.AddCommand(scanCmd)
|
rootCmd.AddCommand(scanCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,9 +73,9 @@ func runScanner(ctx context.Context) {
|
|||||||
|
|
||||||
// Parse targets if provided
|
// Parse targets if provided
|
||||||
var scanTargets []model.ScanTarget
|
var scanTargets []model.ScanTarget
|
||||||
if targets != "" {
|
if len(targets) > 0 {
|
||||||
var err error
|
var err error
|
||||||
scanTargets, err = model.ParseTargets(strings.Split(targets, ","))
|
scanTargets, err = model.ParseTargets(targets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(ctx, "Failed to parse targets", err)
|
log.Fatal(ctx, "Failed to parse targets", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -8,12 +8,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/conf"
|
"github.com/navidrome/navidrome/conf"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils/slice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// scannerExternal is a scanner that runs an external process to do the scanning. It is used to avoid
|
// scannerExternal is a scanner that runs an external process to do the scanning. It is used to avoid
|
||||||
@@ -47,9 +45,10 @@ func (s *scannerExternal) scan(ctx context.Context, fullScan bool, targets []mod
|
|||||||
|
|
||||||
// Add targets if provided
|
// Add targets if provided
|
||||||
if len(targets) > 0 {
|
if len(targets) > 0 {
|
||||||
targetsStr := strings.Join(slice.Map(targets, func(t model.ScanTarget) string { return t.String() }), ",")
|
for _, target := range targets {
|
||||||
args = append(args, "--targets", targetsStr)
|
args = append(args, "-t", target.String())
|
||||||
log.Debug(ctx, "Spawning external scanner process with targets", "fullScan", fullScan, "path", exe, "targets", targetsStr)
|
}
|
||||||
|
log.Debug(ctx, "Spawning external scanner process with targets", "fullScan", fullScan, "path", exe, "targets", targets)
|
||||||
} else {
|
} else {
|
||||||
log.Debug(ctx, "Spawning external scanner process", "fullScan", fullScan, "path", exe)
|
log.Debug(ctx, "Spawning external scanner process", "fullScan", fullScan, "path", exe)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user