Initialize bars in main

This commit is contained in:
2021-08-06 00:18:59 +02:00
parent 1144e97045
commit c090b6645e
2 changed files with 31 additions and 11 deletions

View File

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