1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2025-07-27 12:30:28 +00:00

*.go: ignoreSuffixes to not walk the basedir

and maybe to let the user specify paths too
This commit is contained in:
Vincent Batts 2023-04-12 10:59:00 -04:00
parent 2835d1a77d
commit ef98140425
2 changed files with 32 additions and 3 deletions

View file

@ -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
}