From c090b6645ee0806640b2cf1cf3cb6ecce768c79d Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 6 Aug 2021 00:18:59 +0200 Subject: [PATCH] Initialize bars in main --- filesmap.go | 18 +++++++----------- main.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/filesmap.go b/filesmap.go index 190ad8f..2083db5 100644 --- a/filesmap.go +++ b/filesmap.go @@ -9,7 +9,6 @@ import ( "sync" "github.com/vbauerster/mpb/v7" - "github.com/vbauerster/mpb/v7/decor" ) // FilesMap is a struct for listing files by Size and Hash to search for duplicates @@ -26,6 +25,8 @@ type FilesMap struct { incomingBar *mpb.Bar + hashingBar *mpb.Bar + lock sync.Mutex } @@ -53,6 +54,7 @@ func (fm *FilesMap) HashingWorker(wg *sync.WaitGroup) { } file.hash = hash + fm.hashingBar.IncrInt64(file.size) fm.FilesHashed <- file } wg.Done() @@ -74,16 +76,7 @@ func (fm *FilesMap) HashedWorker(done chan bool) { func (fm *FilesMap) WalkDirectories() int { countFiles := 0 - fm.incomingBar = fm.progress.AddSpinner(0, - mpb.PrependDecorators( - decor.Name("Finding files "), - decor.Elapsed(decor.ET_STYLE_HHMMSS), - ), - mpb.AppendDecorators( - decor.AverageSpeed(0, "%f "), - decor.CountersNoUnit("%d / %d"), - ), - ) + sumSize := int64(0) for _, path := range flag.Args() { filepath.Walk(path, func(path string, info os.FileInfo, err error) error { if info.IsDir() { @@ -109,11 +102,14 @@ func (fm *FilesMap) WalkDirectories() int { } if prevFile != "" { + sumSize += size fm.FilesHashing <- fileEntry{prevFile, size, ""} } fm.FilesBySize[size] = "" + sumSize += size + fm.hashingBar.SetTotal(int64(sumSize), false) fm.FilesHashing <- fileEntry{path, info.Size(), ""} return nil }) diff --git a/main.go b/main.go index 99ef5fd..539d569 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,9 @@ import ( "strconv" "strings" "sync" + + "github.com/vbauerster/mpb/v7" + "github.com/vbauerster/mpb/v7/decor" ) var fromFile = flag.String("from-file", "", "Load results file from ") @@ -51,6 +54,27 @@ func main() { panic(err) } } else { + filesMap.incomingBar = filesMap.progress.AddSpinner(0, + mpb.PrependDecorators( + decor.Name("Finding files "), + decor.Elapsed(decor.ET_STYLE_HHMMSS), + ), + mpb.AppendDecorators( + decor.AverageSpeed(0, "%8.2f"), + decor.Name(" "), + decor.CurrentNoUnit("%5d"), + ), + ) + filesMap.hashingBar = filesMap.progress.AddBar(0, + mpb.PrependDecorators( + decor.Name("Hashing files "), + decor.Elapsed(decor.ET_STYLE_HHMMSS), + ), + mpb.AppendDecorators( + decor.AverageSpeed(decor.UnitKiB, "%23.2f"), + decor.Name(" "), + decor.CurrentKibiByte("%5d"), + )) done := make(chan bool) wg := sync.WaitGroup{} for i := 0; i < runtime.GOMAXPROCS(0); i++ {