From 31383ad118ca94480755f538e059d12c532b3b58 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Thu, 5 Aug 2021 23:21:46 +0200 Subject: [PATCH] Use other progressbar --- filesmap.go | 35 ++++++++++++++++++++++++++++++----- main.go | 7 +------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/filesmap.go b/filesmap.go index daa6eb8..a9cde91 100644 --- a/filesmap.go +++ b/filesmap.go @@ -8,7 +8,8 @@ import ( "path/filepath" "sync" - "github.com/cheggaaa/pb/v3" + "github.com/vbauerster/mpb" + "github.com/vbauerster/mpb/decor" ) // FilesMap is a struct for listing files by Size and Hash to search for duplicates @@ -23,7 +24,9 @@ type FilesMap struct { FilesHashed chan fileEntry - progress *pb.ProgressBar + progress *mpb.Progress + + incomingBar *mpb.Bar lock sync.Mutex } @@ -35,17 +38,21 @@ func newFilesMap() *FilesMap { FilesHashed: make(chan fileEntry), FilesIncoming: make(chan fileEntry, 100000), FilesHashing: make(chan fileEntry), - progress: pb.StartNew(0), + progress: mpb.New(mpb.WithWidth(64)), } } func (fm *FilesMap) IncomingWorker() { for file := range fm.FilesIncoming { + fm.incomingBar.Increment() + if *minSize > file.size { + continue + } + if *verbose { fmt.Println("Incoming", file.path) } - fm.progress.Increment() prevFile, ok := fm.FilesBySize[file.size] if !ok { fm.FilesBySize[file.size] = file.path @@ -102,6 +109,16 @@ func (fm *FilesMap) HashedWorker(done chan bool) { func (fm *FilesMap) WalkDirectories() int { countFiles := 0 + fm.incomingBar = fm.progress.AddSpinner(0, mpb.SpinnerOnLeft, + mpb.PrependDecorators( + // display our name with one space on the right + decor.Name("Finding files"), + // replace ETA decorator with "done" message, OnComplete event + decor.OnComplete( + decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done", + ), + ), + mpb.AppendDecorators(decor.AverageSpeed(1, "%d"), decor.TotalNoUnit("%d"))) for _, path := range flag.Args() { filepath.Walk(path, func(path string, info os.FileInfo, err error) error { if info.IsDir() { @@ -110,11 +127,19 @@ func (fm *FilesMap) WalkDirectories() int { fm.FilesIncoming <- fileEntry{path, info.Size(), ""} countFiles++ - fm.progress.SetTotal(int64(countFiles)) + fm.incomingBar.SetTotal(int64(countFiles), false) + return nil }) } + fm.incomingBar.SetTotal(int64(countFiles), true) close(fm.FilesIncoming) return countFiles } + +type fileEntry struct { + path string + size int64 + hash string +} diff --git a/main.go b/main.go index cad61ab..a62893c 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ var toFile = flag.String("to-file", "", "Save results to ") var deleteDupesIn = flag.String("delete-dupes-in", "", "Delete duplicates if they are contained in ") var promptForDelete = flag.Bool("delete-prompt", false, "Ask which file to keep for each dupe-set") var moveToFolder = flag.String("move-files", "", "Move files to instead of deleting them") +var minSize = flag.Int64("min-size", -1, "Ignore all files smaller than in Bytes") var force = flag.Bool("force", false, "Actually delete files. Without this options, the files to be deleted are only printed") var verbose = flag.Bool("verbose", false, "Output additional information") var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") @@ -189,9 +190,3 @@ func printConfiguration() { fmt.Println() fmt.Println() } - -type fileEntry struct { - path string - size int64 - hash string -}