From a2b5d2e224a2cf4c7be0215c49590247dd12e96a Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Dec 2023 16:33:17 +0100 Subject: [PATCH] Fix file hashing bar being used for images --- filesmap.go | 17 +++++++++-------- main.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/filesmap.go b/filesmap.go index 5efed8e..f36bf1e 100644 --- a/filesmap.go +++ b/filesmap.go @@ -31,7 +31,7 @@ type FilesMap struct { incomingBar *mpb.Bar - hashingBar *mpb.Bar + fileHashingBar *mpb.Bar lock sync.Mutex } @@ -55,7 +55,7 @@ func (fm *FilesMap) FileHashingWorker(wg *sync.WaitGroup) { } hash, err := calculateFileHash(file.path) - fm.hashingBar.IncrInt64(file.size) + fm.fileHashingBar.IncrInt64(file.size) fm.FilesHashed <- file if err != nil { @@ -75,8 +75,7 @@ func (fm *FilesMap) ImageHashingWorker(wg *sync.WaitGroup) { } hash, err := calculateImageHash(file.path) - fm.hashingBar.IncrInt64(file.size) - fm.ImagesHashed <- file + //fm.hashingBar.IncrInt64(file.size) if err != nil { log.Printf("Error calculating Hash for image %s: %v\n", file.path, err) @@ -84,7 +83,6 @@ func (fm *FilesMap) ImageHashingWorker(wg *sync.WaitGroup) { } file.imageHash = hash - fm.hashingBar.IncrInt64(file.size) fm.ImagesHashed <- file } wg.Done() @@ -127,13 +125,16 @@ func (fm *FilesMap) WalkDirectories() int64 { if *minSize > size { return nil } + countFiles++ + fm.incomingBar.SetTotal(int64(countFiles), false) fm.hashImage(path, size) count := fm.hashFile(path, size) - sumSize += size * count - fm.incomingBar.SetTotal(int64(countFiles), false) - fm.hashingBar.SetTotal(int64(sumSize), false) + if count > 0 { + sumSize += size * count + fm.fileHashingBar.SetTotal(int64(sumSize), false) + } return nil }) } diff --git a/main.go b/main.go index 21f586c..11e8e87 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func main() { decor.CurrentNoUnit("%5d"), ), ) - filesMap.hashingBar = filesMap.progress.AddBar(0, + filesMap.fileHashingBar = filesMap.progress.AddBar(0, mpb.PrependDecorators( decor.Name("Hashing files "), decor.Elapsed(decor.ET_STYLE_HHMMSS),