Make scan paths required operands; add -x/--one-file-system
All checks were successful
check / check (push) Successful in 4s
All checks were successful
check / check (push) Successful in 4s
scan now takes one or more PATH operands (directories or regular files) via cobra flags instead of the -root flag with its /srv default; invoking scan with no operand is a usage error and a nonexistent operand is fatal. Filesystem boundaries are crossed by default; the new -x/--one-file-system flag (GNU du/rsync convention) stops the walk at each operand's filesystem, implemented by comparing lstat device IDs with build-tagged helpers for darwin's int32 Dev. Verified against a real mounted disk image: default crosses, -x does not, --one-file-system is identical to -x.
This commit is contained in:
22
main.go
22
main.go
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// sfdupes scan [-root /srv] [-workers N] > files.dat
|
||||
// sfdupes scan [--workers N] [-x] PATH... > files.dat
|
||||
// sfdupes report [files.dat|-] > dupes.tsv
|
||||
// sfdupes trees [files.dat|-] > dupetrees.tsv
|
||||
//
|
||||
@@ -16,6 +16,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -52,16 +53,23 @@ func main() {
|
||||
root.SetErr(os.Stderr)
|
||||
root.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
var (
|
||||
scanWorkers int
|
||||
scanOneFS bool
|
||||
)
|
||||
|
||||
scanCmd := &cobra.Command{
|
||||
Use: "scan [-root /srv] [-workers N]",
|
||||
Short: "Walk a tree and emit one record per regular file on stdout",
|
||||
// The README specifies single-dash flags (-root, -workers);
|
||||
// parse them with the stdlib flag package inside runScan.
|
||||
DisableFlagParsing: true,
|
||||
Use: "scan [--workers N] [-x] PATH...",
|
||||
Short: "Walk trees and emit one record per regular file on stdout",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
runScan(args)
|
||||
runScan(args, scanWorkers, scanOneFS)
|
||||
},
|
||||
}
|
||||
scanCmd.Flags().IntVar(&scanWorkers, "workers", runtime.NumCPU(),
|
||||
"concurrent workers for the stat and hash passes")
|
||||
scanCmd.Flags().BoolVarP(&scanOneFS, "one-file-system", "x", false,
|
||||
"do not cross filesystem boundaries")
|
||||
|
||||
reportCmd := &cobra.Command{
|
||||
Use: "report [files.dat|-]",
|
||||
|
||||
Reference in New Issue
Block a user