diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -1183,7 +1183,7 @@ func syncDirectory(c *syncContext, dbParent int64, fsPath string) error { return nil } -func syncArgument(ctx context.Context, tx *sql.Tx, path string) error { +func syncRoot(ctx context.Context, tx *sql.Tx, fsPath string) error { c := syncContext{ctx: ctx, tx: tx} c.pb = newProgressBar(-1) @@ -1210,12 +1210,6 @@ func syncArgument(ctx context.Context, tx *sql.Tx, path string) error { // i.e., it is for the result of the task that syncEnqueue() spawns. c.info = make(chan syncFileInfo, cap(taskSemaphore)+1) - // At least for now, turn all roots into absolute paths. - fsPath, err := filepath.Abs(filepath.Clean(path)) - if err != nil { - return err - } - // Figure out a database root (not trying to convert F → D on conflict, // also because we don't know yet if the argument is a directory). // @@ -1282,11 +1276,28 @@ func cmdSync(args []string) error { ctxSignal, stop := signal.NotifyContext(ctx, os.Interrupt) defer stop() - // TODO: Check if one is not a prefix of another, - // and either filter out these duplicates (easy to do, may warn), - // or plainly refuse to work. - for _, path := range args[1:] { - if err := syncArgument(ctxSignal, tx, path); err != nil { + // Normalize arguments. + // At least for now, turn all roots into absolute paths. + roots := args[1:] + for i := range roots { + roots[i], err = filepath.Abs(filepath.Clean(roots[i])) + if err != nil { + return err + } + } + + // Filter out duplicates. + sort.Strings(roots) + roots = slices.CompactFunc(roots, func(a, b string) bool { + if a != b && !strings.HasPrefix(b, a+"/") { + return false + } + log.Printf("asking to sync path twice: %s\n", b) + return true + }) + + for _, path := range roots { + if err := syncRoot(ctxSignal, tx, path); err != nil { return err } } |