diff --git a/file/hash.go b/file/hash.go index 8c8e9fe..309e002 100644 --- a/file/hash.go +++ b/file/hash.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "strings" "time" ) @@ -23,13 +24,21 @@ type HashInfo struct { // HashFileGetter walks the provided `path` with `workers` number of threads. // The channel of HashInfo are for each regular file encountered. -func HashFileGetter(path string, hash crypto.Hash, workers int, done <-chan struct{}) <-chan HashInfo { +func HashFileGetter(path string, hash crypto.Hash, ignoreSuffixes []string, workers int, done <-chan struct{}) <-chan HashInfo { out := make(chan HashInfo, workers) go func() { err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { if err != nil { return err } + for _, suff := range ignoreSuffixes { + if os.Getenv("DEBUG") != "" { + fmt.Printf("[DEBUG] path: %q ; suff: %q\n", filepath.Clean(path), filepath.Clean(suff)) + } + if strings.HasSuffix(filepath.Clean(path), filepath.Clean(suff)) { + return filepath.SkipDir + } + } if !info.Mode().IsRegular() { return nil } diff --git a/main.go b/main.go index 6dd9e17..7442d61 100644 --- a/main.go +++ b/main.go @@ -58,11 +58,31 @@ func main() { } var ( - hash = cryptomap.DetermineHash(*flCipher) + ignoreSuffixes = []string{} + hash = cryptomap.DetermineHash(*flCipher) //infos = []*file.HashInfo{} //results := make(chan file.HashInfo, 2) ) + bpath, err := filepath.Abs(*flVarBase) + if err != nil { + log.Fatal(err) + } + for _, arg := range flag.Args() { + apath, err := filepath.Abs(arg) + if err != nil { + log.Fatal(err) + } + rel, err := filepath.Rel(apath, bpath) + if err != nil { + log.Fatal(err) + } + ignoreSuffixes = append(ignoreSuffixes, rel) + } + if os.Getenv("DEBUG") != "" { + fmt.Printf("[DEBUG] ignoreSuffixes: %#v\n", ignoreSuffixes) + } + for _, arg := range flag.Args() { if !*flNoop { if m, err := file.SameDevPaths(*flVarBase, arg); err != nil { @@ -73,7 +93,7 @@ func main() { } } done := make(chan struct{}) - infos := file.HashFileGetter(arg, hash, *flWorkers, done) + infos := file.HashFileGetter(arg, hash, ignoreSuffixes, *flWorkers, done) for fi := range infos { if fi.Err != nil { log.Println(fi.Err)