|
@@ -15,6 +15,8 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
+ "code.cloudfoundry.org/bytefmt"
|
|
|
+
|
|
|
flag "github.com/spf13/pflag"
|
|
|
)
|
|
|
|
|
@@ -229,6 +231,51 @@ func loadHashfile(fileStr string) Fdhashes {
|
|
|
|
|
|
func compareFolder(folder string) {
|
|
|
loadAllHashFiles(folder)
|
|
|
+
|
|
|
+ index := make(map[string][]string)
|
|
|
+
|
|
|
+ for _, hashFile := range hashes {
|
|
|
+ for filename, hash := range hashFile.Hashes {
|
|
|
+ values := index[hash]
|
|
|
+ if values == nil {
|
|
|
+ values = make([]string, 0)
|
|
|
+ }
|
|
|
+ values = append(values, fmt.Sprintf("%s/%s", hashFile.Path, filename))
|
|
|
+ index[hash] = values
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ size := len(index)
|
|
|
+ f, err := os.Create("report.txt")
|
|
|
+ check(err)
|
|
|
+ w := bufio.NewWriter(f)
|
|
|
+ count := 0
|
|
|
+ var filesize int64
|
|
|
+ fileCount := 0
|
|
|
+ for _, values := range index {
|
|
|
+ count++
|
|
|
+ if count%100 == 0 {
|
|
|
+ fmt.Printf("%d (%d) checking\n", count, size)
|
|
|
+ }
|
|
|
+ if len(values) > 1 {
|
|
|
+ info, err := os.Stat(values[0])
|
|
|
+ if err == nil {
|
|
|
+ w.WriteString(fmt.Sprintf("found identically hash: size: %d\n", info.Size()))
|
|
|
+ filesize += int64(len(values)-1) * info.Size()
|
|
|
+ }
|
|
|
+ fileCount += len(values) - 1
|
|
|
+ for _, filename := range values {
|
|
|
+ w.WriteString(fmt.Sprintf(" %s\n", filename))
|
|
|
+ }
|
|
|
+ w.Flush()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ w.WriteString(fmt.Sprintf("can save up to %s on %d files\n", bytefmt.ByteSize(uint64(filesize)), fileCount))
|
|
|
+ w.Flush()
|
|
|
+}
|
|
|
+
|
|
|
+func compareFolder2(folder string) {
|
|
|
+ loadAllHashFiles(folder)
|
|
|
size := len(hashes)
|
|
|
f, err := os.Create("report.txt")
|
|
|
check(err)
|