|
@@ -12,6 +12,7 @@ import (
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"runtime"
|
|
|
+ "sort"
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
@@ -270,8 +271,8 @@ func loadHashfile(fileStr string) Fdhashes {
|
|
|
func compareFolder(folder string) {
|
|
|
loadAllHashFiles(folder)
|
|
|
|
|
|
+ // putting all hashes into one big map key = hash, value list of files with that hash
|
|
|
index := make(map[string][]string)
|
|
|
-
|
|
|
for _, hashFile := range hashes {
|
|
|
for filename, hash := range hashFile.Hashes {
|
|
|
values := index[hash]
|
|
@@ -283,11 +284,33 @@ func compareFolder(folder string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // sorting list of files for every hash and deleting hashes with only 1 entry
|
|
|
+ size := len(index)
|
|
|
+ myHashes := make([]string, 0)
|
|
|
+ for hash, values := range index {
|
|
|
+ count++
|
|
|
+ if count%100 == 0 {
|
|
|
+ fmt.Printf("%d (%d) sorting\n", count, size)
|
|
|
+ }
|
|
|
+ if len(values) > 1 {
|
|
|
+ sort.Strings(values)
|
|
|
+ index[hash] = values
|
|
|
+ myHashes = append(myHashes, hash)
|
|
|
+ // for _, filename := range values {
|
|
|
+ // fmt.Printf(" %s\n", filename)
|
|
|
+ // }
|
|
|
+ } else {
|
|
|
+ delete(index, hash)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort.Slice(myHashes, func(i, j int) bool { return index[myHashes[i]][0] < index[myHashes[j]][0] })
|
|
|
+
|
|
|
if outputJson {
|
|
|
- size := len(index)
|
|
|
+ size = len(index)
|
|
|
var filesize int64
|
|
|
fileCount := 0
|
|
|
- for hash, values := range index {
|
|
|
+ for _, hash := range myHashes {
|
|
|
+ values := index[hash]
|
|
|
count++
|
|
|
if count%100 == 0 {
|
|
|
fmt.Printf("%d (%d) checking\n", count, size)
|
|
@@ -324,7 +347,8 @@ func compareFolder(folder string) {
|
|
|
count := 0
|
|
|
var filesize int64
|
|
|
fileCount := 0
|
|
|
- for _, values := range index {
|
|
|
+ for _, hash := range myHashes {
|
|
|
+ values := index[hash]
|
|
|
count++
|
|
|
if count%100 == 0 {
|
|
|
fmt.Printf("%d (%d) checking\n", count, size)
|