mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-05-18 06:01:56 +02:00
Initialize bars in main
This commit is contained in:
parent
1144e97045
commit
c090b6645e
18
filesmap.go
18
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
|
||||
})
|
||||
|
24
main.go
24
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 <path>")
|
||||
@ -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++ {
|
||||
|
Loading…
x
Reference in New Issue
Block a user