mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-05-18 06:01:56 +02:00
Use other progressbar
This commit is contained in:
parent
275b63cfe8
commit
31383ad118
35
filesmap.go
35
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
|
||||
}
|
||||
|
7
main.go
7
main.go
@ -21,6 +21,7 @@ var toFile = flag.String("to-file", "", "Save results to <path>")
|
||||
var deleteDupesIn = flag.String("delete-dupes-in", "", "Delete duplicates if they are contained in <path>")
|
||||
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 <path> instead of deleting them")
|
||||
var minSize = flag.Int64("min-size", -1, "Ignore all files smaller than <size> 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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user