Display statistics

This commit is contained in:
Jan Bader 2020-11-22 01:57:24 +01:00
parent 594a88c3ec
commit 66a9ae73e5
2 changed files with 18 additions and 3 deletions

View File

@ -94,7 +94,8 @@ func (fm *FilesMap) HashedWorker(done chan bool) {
done <- true done <- true
} }
func (fm *FilesMap) WalkDirectories() { func (fm *FilesMap) WalkDirectories() int {
countFiles := 0
for _, path := range flag.Args() { for _, path := range flag.Args() {
filepath.Walk(path, func(path string, info os.FileInfo, err error) error { filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if info.IsDir() { if info.IsDir() {
@ -102,9 +103,11 @@ func (fm *FilesMap) WalkDirectories() {
} }
fm.FilesIncoming <- fileEntry{path, info.Size(), ""} fm.FilesIncoming <- fileEntry{path, info.Size(), ""}
countFiles++
return nil return nil
}) })
} }
close(fm.FilesIncoming) close(fm.FilesIncoming)
return countFiles
} }

16
main.go
View File

@ -40,7 +40,7 @@ func main() {
if *verbose { if *verbose {
printConfiguration() printConfiguration()
} }
countFiles := 0
filesMap := newFilesMap() filesMap := newFilesMap()
if *fromFile != "" { if *fromFile != "" {
byteValue, _ := ioutil.ReadFile(*fromFile) byteValue, _ := ioutil.ReadFile(*fromFile)
@ -60,7 +60,7 @@ func main() {
go filesMap.HashedWorker(done) go filesMap.HashedWorker(done)
filesMap.WalkDirectories() countFiles = filesMap.WalkDirectories()
wg.Wait() wg.Wait()
close(filesMap.FilesHashed) close(filesMap.FilesHashed)
@ -128,17 +128,29 @@ func main() {
} }
} }
} else { } else {
countInstances := 0
countDupeSets := 0
for hash := range filesMap.FilesByHash { for hash := range filesMap.FilesByHash {
duplicateFiles := filesMap.FilesByHash[hash] duplicateFiles := filesMap.FilesByHash[hash]
if len(duplicateFiles) <= 1 { if len(duplicateFiles) <= 1 {
continue continue
} }
countDupeSets++
for _, file := range duplicateFiles { for _, file := range duplicateFiles {
countInstances++
fmt.Println(file) fmt.Println(file)
} }
fmt.Println() fmt.Println()
} }
fmt.Println("Statistics:")
fmt.Println(countFiles, "Files")
fmt.Println(len(filesMap.FilesBySize), "Unique Sizes")
fmt.Println(len(filesMap.FilesByHash), "Unique Hashes")
fmt.Println(countInstances, "Duplicate Files")
fmt.Println(countDupeSets, "Duplicate Sets")
} }
} }