Add progress bar for initial walk

This commit is contained in:
Jan Bader 2020-11-26 14:52:33 +01:00
parent 3c3f1d747b
commit 8f0f32d5ee
2 changed files with 9 additions and 1 deletions

View File

@ -7,6 +7,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"github.com/cheggaaa/pb/v3"
) )
// FilesMap is a struct for listing files by Size and Hash to search for duplicates // FilesMap is a struct for listing files by Size and Hash to search for duplicates
@ -21,6 +23,8 @@ type FilesMap struct {
FilesHashed chan fileEntry FilesHashed chan fileEntry
progress *pb.ProgressBar
lock sync.Mutex lock sync.Mutex
} }
@ -29,8 +33,9 @@ func newFilesMap() *FilesMap {
FilesBySize: map[int64]string{}, FilesBySize: map[int64]string{},
FilesByHash: map[string][]string{}, FilesByHash: map[string][]string{},
FilesHashed: make(chan fileEntry), FilesHashed: make(chan fileEntry),
FilesIncoming: make(chan fileEntry), FilesIncoming: make(chan fileEntry, 100000),
FilesHashing: make(chan fileEntry), FilesHashing: make(chan fileEntry),
progress: pb.StartNew(0),
} }
} }
@ -40,6 +45,7 @@ func (fm *FilesMap) IncomingWorker() {
fmt.Println("Incoming", file.path) fmt.Println("Incoming", file.path)
} }
fm.progress.Increment()
prevFile, ok := fm.FilesBySize[file.size] prevFile, ok := fm.FilesBySize[file.size]
if !ok { if !ok {
fm.FilesBySize[file.size] = file.path fm.FilesBySize[file.size] = file.path
@ -104,6 +110,7 @@ func (fm *FilesMap) WalkDirectories() int {
fm.FilesIncoming <- fileEntry{path, info.Size(), ""} fm.FilesIncoming <- fileEntry{path, info.Size(), ""}
countFiles++ countFiles++
fm.progress.SetTotal(int64(countFiles))
return nil return nil
}) })
} }

View File

@ -103,6 +103,7 @@ func main() {
fmt.Println() fmt.Println()
continue continue
} }
for _, file := range duplicateFiles { for _, file := range duplicateFiles {
if strings.HasPrefix(filepath.Clean(file), deleteIn) { if strings.HasPrefix(filepath.Clean(file), deleteIn) {
fmt.Println("Would delete ", file) fmt.Println("Would delete ", file)