23 Commits 20ce85fac7 ... 2751bbe632

Author SHA1 Message Date
  Wilfried Klaas 2751bbe632 Merge branch 'develop' 2 years ago
  Wilfried Klaas edb3a2ea2d refactoring the hash as lib 2 years ago
  Klaas, Wilfried 5fc2ba7f22 only some testing. 3 years ago
  Wilfried Klaas 3815083dfa adding ignore file list for reporting 4 years ago
  Wilfried Klaas 3e8fd7f43c new sorting options 4 years ago
  willie ab50f71a65 sorting report 4 years ago
  Klaas, Wilfried 9cedf1162c change 4 years ago
  Klaas, Wilfried e89593de7a change cleanup to json 4 years ago
  Klaas, Wilfried a585be9143 small changes 4 years ago
  willie e9c90cab85 orthografic bug 4 years ago
  Klaas, Wilfried 91b20b8e4b adding new feature 4 years ago
  willie b07b1dd33f lesser go procs... 4 years ago
  Klaas, Wilfried 38166cdf64 faster report generation 4 years ago
  Klaas, Wilfried b6b46a723d first report version 4 years ago
  Klaas, Wilfried eff61c20cf more performance 4 years ago
  Klaas, Wilfried e06859cde5 adding locks 4 years ago
  Klaas, Wilfried 92c3bf0748 new version with rewrite parameter and better performance and timestamp. 4 years ago
  Klaas, Wilfried 41fffcafa6 Auto stash before merge of "develop" and "origin/develop" 4 years ago
  Wilfried Klaas 7be2de32aa Auto stash before merge of "develop" and "origin/develop" 4 years ago
  Klaas, Wilfried 18a5e346c2 eleminating panic with more detailed log.Fatalf 4 years ago
  Klaas, Wilfried 51b956c7f2 merged to module version 4 years ago
  willie a2d4508880 adding license 4 years ago
  willie 334d20e404 removing visual studion files 4 years ago
11 changed files with 637 additions and 162 deletions
  1. 2 0
      .gitignore
  2. 12 4
      .vscode/launch.json
  3. 0 4
      .vscode/settings.json
  4. 0 16
      .vscode/tasks.json
  5. 0 135
      GoHash.go
  6. 72 0
      LICENSE
  7. 3 3
      build.cmd
  8. 433 0
      cmd/main.go
  9. 10 0
      go.mod
  10. 94 0
      go.sum
  11. 11 0
      gohash.code-workspace

+ 2 - 0
.gitignore

@@ -2,3 +2,5 @@
 *.exe
 pkg
 src/github.com
+__debug_bin
+report.txt

+ 12 - 4
.vscode/launch.json

@@ -5,15 +5,23 @@
     "version": "0.2.0",
     "configurations": [
         {
-            "name": "Launch",
+            "name": "GoHash Report",
             "type": "go",
             "request": "launch",
             "mode": "auto",
             "program": "${fileDirname}",
             "env": {},
-            "args": [
-                "e:\\temp"
-            ]
+            "args": ["-i", "G:\\ignores.lst", "-e", "G:\\report_vids.txt", "G:\\noShare\\vids" ]
+        },
+        {
+            "name": "GoHash Hash",
+            "type": "go",
+            "request": "launch",
+            "mode": "debug",
+            "cwd": "${workspaceFolder}",
+            "program": "./cmd/main.go",
+            "env": {},
+            "args": ["C:\\e-platte\\temp\\R2D2" ]
         }
     ]
 }

+ 0 - 4
.vscode/settings.json

@@ -1,4 +0,0 @@
-{
-    "go.inferGopath": true,
-    "go.gopath": "E:\\daten\\git-sourcen\\GoHash"
-}

+ 0 - 16
.vscode/tasks.json

@@ -1,16 +0,0 @@
-{
-    // See https://go.microsoft.com/fwlink/?LinkId=733558
-    // for the documentation about the tasks.json format
-    "version": "2.0.0",
-    "tasks": [
-        {
-            "label": "Build and run",
-            "type": "shell",
-            "command": "go build",
-            "group": {
-                "kind": "build",
-                "isDefault": true
-            }
-        }
-    ]
-}

+ 0 - 135
GoHash.go

@@ -1,135 +0,0 @@
-package main
-
-import (
-	"crypto/sha256"
-	"encoding/hex"
-	"encoding/json"
-	"flag"
-	"fmt"
-	"io"
-	"io/ioutil"
-	"log"
-	"os"
-	"path/filepath"
-	"runtime"
-	"sync"
-)
-
-type Fdhashes struct {
-	Path   string
-	Hashes map[string]string
-}
-
-var hashes map[string]Fdhashes
-
-var wg sync.WaitGroup
-var mu sync.RWMutex
-
-func main() {
-	runtime.GOMAXPROCS(5)
-	hashes = make(map[string]Fdhashes)
-	flag.Parse()
-	myFile := flag.Arg(0)
-	file, err := os.Stat(myFile)
-	if os.IsNotExist(err) {
-		log.Fatalln("File does not exists:", myFile)
-	}
-	if file.IsDir() {
-		log.Println("start with folder:", myFile)
-		processFolder(myFile)
-	} else {
-		log.Printf("file %s has hash %s\n", myFile, getHash(myFile))
-	}
-
-	fmt.Println("waiting")
-	wg.Wait()
-	log.Println("done")
-}
-
-func getHash(fileStr string) string {
-	f, err := os.Open(fileStr)
-	if err != nil {
-		log.Fatal(err)
-	}
-	defer f.Close()
-
-	h := sha256.New()
-	if _, err := io.Copy(h, f); err != nil {
-		log.Fatal(err)
-	}
-	return hex.EncodeToString(h.Sum(nil))
-}
-
-func outputHash(fileStr string) {
-	var hashFile Fdhashes
-	doHash := true
-	defer wg.Done()
-	fmt.Print(".")
-	dir, fileName := filepath.Split(fileStr)
-	if fileName == ".fdhashes3" {
-		return
-	}
-	mu.Lock()
-	hashFile, ok := hashes[dir]
-	if !ok {
-		_, err := os.Stat(dir + ".fdhashes3")
-		if os.IsNotExist(err) {
-			hashFile = Fdhashes{Path: dir, Hashes: make(map[string]string)}
-		} else {
-			hashFile = loadHashfile(dir + ".fdhashes3")
-		}
-		hashes[dir] = hashFile
-		saveHashfile(hashFile)
-	}
-
-	_, ok = hashFile.Hashes[fileName]
-	doHash = !ok
-	hashFile = hashes[dir]
-	mu.Unlock()
-	if doHash {
-		hash := getHash(fileStr)
-		mu.Lock()
-		hashFile.Hashes[fileName] = hash
-		saveHashfile(hashFile)
-		mu.Unlock()
-		log.Printf("file %s has hash %s\n", fileStr, hash)
-	}
-}
-
-func processFolder(folder string) {
-	err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
-		if !info.IsDir() {
-			wg.Add(1)
-			go outputHash(path)
-		}
-		return nil
-	})
-	if err != nil {
-		panic(err)
-	}
-}
-
-func saveHashfile(hashFile Fdhashes) {
-	b, err := json.Marshal(hashFile)
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	err = ioutil.WriteFile(hashFile.Path+".fdhashes3", b, 0644)
-	if err != nil {
-		panic(err)
-	}
-}
-
-func loadHashfile(filename string) Fdhashes {
-	file, err := ioutil.ReadFile(filename)
-	if err != nil {
-		panic(err)
-	}
-	data := Fdhashes{}
-	err = json.Unmarshal([]byte(file), &data)
-	if err != nil {
-		panic(err)
-	}
-	return data
-}

+ 72 - 0
LICENSE

@@ -0,0 +1,72 @@
+Apache License 
+Version 2.0, January 2004 
+http://www.apache.org/licenses/
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
+
+(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
+
+(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+
+(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License"); 
+you may not use this file except in compliance with the License. 
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software 
+distributed under the License is distributed on an "AS IS" BASIS, 
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+See the License for the specific language governing permissions and 
+limitations under the License.

+ 3 - 3
build.cmd

@@ -1,3 +1,3 @@
-@echo off
-set GOPATH=%cd%
-go build 
+del GoHash.exe
+go build -o GoHash.exe -ldflags="-s -w" cmd/main.go
+copy GoHash.exe G:\

+ 433 - 0
cmd/main.go

@@ -0,0 +1,433 @@
+package main
+
+import (
+	"bufio"
+	"crypto/sha256"
+	"encoding/hex"
+	"encoding/json"
+	"fmt"
+	"io"
+	"io/ioutil"
+	"log"
+	"os"
+	"path/filepath"
+	"sort"
+	"strings"
+	"sync"
+	"time"
+
+	"code.cloudfoundry.org/bytefmt"
+
+	flag "github.com/spf13/pflag"
+	"wkla.no-ip.biz/gogs/Willie/GoHash/pkg/hash"
+)
+
+var hashes map[string]hash.Fdhashes
+var ignoreLines []string
+var mu sync.RWMutex
+
+var rewrite bool
+var prune bool
+var outputJson bool
+var report string
+var ignores string
+
+func init() {
+	flag.BoolVarP(&rewrite, "rewrite", "r", false, "rewrite all fhhashes files.")
+	flag.StringVarP(&report, "equals", "e", "", "compare all file hashes and writing a equlatity report.")
+	flag.BoolVarP(&prune, "prune", "p", false, "checking all fdhashes files.")
+	flag.BoolVarP(&outputJson, "json", "j", false, "output as json.")
+	flag.StringVarP(&ignores, "ignores", "i", "", "list of files to ignore in report.")
+}
+
+func main() {
+	log.Println("starting GoHash")
+	ignoreLines = make([]string, 0)
+	hashes = make(map[string]hash.Fdhashes)
+	flag.Parse()
+	myFile := flag.Arg(0)
+	if rewrite {
+		log.Println("rewrite active")
+	}
+	if prune {
+		log.Println("prune active")
+	}
+	if outputJson {
+		log.Println("output json format active")
+	}
+	if report != "" {
+		log.Println("report active, file: ", report)
+	}
+	if ignores != "" {
+		log.Println("ignores file: ", ignores)
+	}
+	file, err := os.Stat(myFile)
+	if os.IsNotExist(err) {
+		log.Fatalln("File does not exists:", myFile)
+	}
+	if file.IsDir() {
+		log.Println("start with folder:", myFile)
+
+		if report != "" {
+			compareFolder(myFile)
+		} else {
+			processFolder(myFile)
+			saveAllHashFiles()
+		}
+	} else {
+		log.Printf("file %s has hash %s\n", myFile, getSha256Hash(myFile))
+	}
+
+	log.Println("done")
+}
+
+func getSha256Hash(fileStr string) string {
+	f, err := os.Open(fileStr)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer f.Close()
+
+	h := sha256.New()
+	if _, err := io.Copy(h, f); err != nil {
+		log.Fatal(err)
+	}
+	return hex.EncodeToString(h.Sum(nil))
+}
+
+var lock1 = sync.RWMutex{}
+var lock2 = sync.RWMutex{}
+
+func calculateHash(fileStr string) {
+	var hashFile hash.Fdhashes
+	doHash := true
+	dir, fileName := filepath.Split(fileStr)
+	if fileName == ".fdhashes3" {
+		return
+	}
+	// checking if hash is present
+	mu.Lock()
+	hashFile, ok := hashes[dir]
+	if !ok {
+		_, err := os.Stat(dir + ".fdhashes3")
+		if os.IsNotExist(err) || rewrite {
+			hashFile = hash.Fdhashes{Path: dir, Hashes: make(map[string]string), Times: make(map[string]time.Time), Dirty: true}
+		} else {
+			hf, err := hash.LoadHashfile(dir + ".fdhashes3")
+			check(err)
+			hashFile = *hf
+		}
+		hashes[dir] = hashFile
+	}
+	lock1.RLock()
+	_, ok = hashFile.Hashes[fileName]
+	lock1.RUnlock()
+	mu.Unlock()
+	doHash = !ok
+	// checking if dattime is identically
+	file, _ := os.Stat(fileStr)
+	time := file.ModTime()
+	lock2.RLock()
+	savedTime, ok := hashFile.Times[fileName]
+	lock2.RUnlock()
+	if !time.Equal(savedTime) || !ok {
+		doHash = true
+	}
+	if doHash {
+		log.Printf("starting %s\n", fileStr)
+		hash := getSha256Hash(fileStr)
+		log.Printf("ready %s\n", fileStr)
+		mu.Lock()
+		lock1.Lock()
+		hashFile.Hashes[fileName] = hash
+		lock1.Unlock()
+
+		lock2.Lock()
+		hashFile.Times[fileName] = time
+		lock2.Unlock()
+		dirtyHashfile(&hashFile)
+		hashes[dir] = hashFile
+		mu.Unlock()
+		log.Printf("file \"%s\" has hash \"%s\"\n", fileStr, hash)
+	}
+}
+
+var count int
+var addWork int
+var startTime time.Time
+
+func processFolder(folder string) {
+	startTime = time.Now()
+	count = 0
+	addWork = 0
+	err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
+		count++
+		if (count % 100) == 0 {
+			fmt.Print(".")
+		}
+		if (count % 10000) == 0 {
+			fmt.Println()
+		}
+		filename := info.Name()
+		if filename[0:1] != "." {
+			if info.IsDir() {
+				fmt.Println(path)
+				if prune {
+					pruneHash(path)
+				}
+			}
+			if !info.IsDir() {
+				addWork++
+				calculateHash(path)
+				if time.Since(startTime).Seconds() > 10.0 {
+					startTime = time.Now()
+					saveAllHashFiles()
+					addWork = 0
+				}
+			}
+		}
+		return nil
+	})
+	if err != nil {
+		panic(err)
+	}
+}
+
+/* delete unused hash values from the hash file */
+func pruneHash(dir string) {
+	_, err := os.Stat(dir + "/.fdhashes3")
+	if !os.IsNotExist(err) {
+		hashFile, err := hash.LoadHashfile(dir + "/.fdhashes3")
+		check(err)
+		for filename := range hashFile.Hashes {
+			_, err := os.Stat(dir + "/" + filename)
+			if os.IsNotExist(err) {
+				delete(hashFile.Hashes, filename)
+				delete(hashFile.Times, filename)
+				hashFile.Dirty = true
+			}
+		}
+
+		for filename := range hashFile.Times {
+			_, err := os.Stat(dir + "/" + filename)
+			if os.IsNotExist(err) {
+				delete(hashFile.Hashes, filename)
+				delete(hashFile.Times, filename)
+				hashFile.Dirty = true
+			}
+		}
+		saveHashfile(hashFile)
+	}
+}
+
+func dirtyHashfile(hashFile *hash.Fdhashes) {
+	hashFile.Dirty = true
+}
+
+func saveAllHashFiles() {
+	hashList := make([]hash.Fdhashes, 0)
+
+	for _, hashFile := range hashes {
+		if hashFile.Dirty {
+			saveHashfile(&hashFile)
+			hashList = append(hashList, hashFile)
+		}
+	}
+
+	hashes = make(map[string]hash.Fdhashes)
+	for _, hashFile := range hashList {
+		hashes[hashFile.Path] = hashFile
+	}
+
+}
+
+func saveHashfile(hashFile *hash.Fdhashes) {
+	if hashFile.Dirty {
+		hashFile.Dirty = false
+		b, err := json.Marshal(hashFile)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		err = ioutil.WriteFile(hashFile.Path+"/.fdhashes3", b, 0644)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+func compareFolder(folder string) {
+	loadIgnoreFile(ignores)
+	loadAllHashFiles(folder)
+	// putting all hashes into one big map key = hash, value list of files with that hash
+	size := len(hashes)
+	index := make(map[string][]string)
+	count = 0
+	for _, hashFile := range hashes {
+		count++
+		if count%100 == 0 {
+			fmt.Printf("%d (%d) merging\n", count, size)
+		}
+		for filename, hash := range hashFile.Hashes {
+			values := index[hash]
+			if values == nil {
+				values = make([]string, 0)
+			}
+			filepath := fmt.Sprintf("%s/%s", hashFile.Path, filename)
+			pos := sort.SearchStrings(ignoreLines, filepath)
+			if pos == len(ignoreLines) {
+				_, err := os.Stat(filepath)
+				if err == nil {
+					values = append(values, filepath)
+					index[hash] = values
+				}
+			}
+		}
+	}
+
+	// sorting list of files for every hash and deleting hashes with only 1 entry
+	size = len(index)
+	myHashes := make([]string, 0)
+	count = 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)
+		var filesize int64
+		fileCount := 0
+		for _, hash := range myHashes {
+			values := index[hash]
+			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 {
+					fmt.Printf("found identically hash: %s size: %d\n", hash, info.Size())
+					filesize += int64(len(values)-1) * info.Size()
+				}
+				fileCount += len(values) - 1
+				for _, filename := range values {
+					fmt.Printf("  %s\n", filename)
+				}
+			} else {
+				delete(index, hash)
+			}
+		}
+
+		b, err := json.Marshal(index)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		err = ioutil.WriteFile(report, b, 0644)
+		if err != nil {
+			panic(err)
+		}
+	} else {
+		size := len(index)
+		f, err := os.Create(report)
+		check(err)
+		w := bufio.NewWriter(f)
+		count := 0
+		var filesize int64
+		fileCount := 0
+		for _, hash := range myHashes {
+			values := index[hash]
+			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 loadIgnoreFile(filename string) {
+	content, err := ioutil.ReadFile(filename)
+	if err == nil {
+		ignoreLines = strings.Split(string(content), "\n")
+		sort.Strings(ignoreLines)
+	}
+}
+
+func search(srcHash string, exFilename string, exFilepath string) (value string, found bool) {
+	for _, hashFile := range hashes {
+		for filename, hash := range hashFile.Hashes {
+			if (filename != exFilename) && (hashFile.Path != exFilepath) {
+				if hash == srcHash {
+					value += fmt.Sprintf("%s/%s;", hashFile.Path, filename)
+					found = true
+				}
+			}
+		}
+	}
+	return
+}
+
+func loadAllHashFiles(folder string) {
+	count = 0
+	addWork = 0
+	err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
+		if info != nil {
+			if info.IsDir() {
+				count++
+				fmt.Print(".")
+				if (count % 100) == 0 {
+					fmt.Println()
+				}
+				hashFile, ok := hashes[path]
+				if !ok {
+					_, err := os.Stat(path + "/.fdhashes3")
+					if os.IsNotExist(err) {
+						hashFile = hash.Fdhashes{Path: path, Hashes: make(map[string]string), Times: make(map[string]time.Time), Dirty: true}
+					} else {
+						hf, err := hash.LoadHashfile(path + "/.fdhashes3")
+						check(err)
+						hashFile = *hf
+					}
+					hashes[path] = hashFile
+				}
+			}
+		}
+		return nil
+	})
+	check(err)
+	fmt.Printf("\nfound %d hash files.\n", len(hashes))
+}
+
+func check(e error) {
+	if e != nil {
+		panic(e)
+	}
+}

+ 10 - 0
go.mod

@@ -0,0 +1,10 @@
+module wkla.no-ip.biz/gogs/Willie/GoHash
+
+// github.com/willie/gohash
+
+go 1.17
+
+require (
+	code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
+	github.com/spf13/pflag v1.0.5
+)

+ 94 - 0
go.sum

@@ -0,0 +1,94 @@
+code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5 h1:tM5+dn2C9xZw1RzgI6WTQW1rGqdUimKB3RFbyu4h6Hc=
+code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5/go.mod h1:v4VVB6oBMz/c9fRY6vZrwr5xKRWOH5NPDjQZlPk0Gbs=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
+github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
+github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
+github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
+github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
+github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
+github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
+github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
+github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
+github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
+github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
+github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
+golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

+ 11 - 0
gohash.code-workspace

@@ -0,0 +1,11 @@
+{
+	"folders": [
+		{
+			"path": "."
+		},
+		{
+			"path": "..\\VideoCat"
+		}
+	],
+	"settings": {}
+}