|
@@ -2,11 +2,8 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"bufio"
|
|
"bufio"
|
|
- "crypto/sha256"
|
|
|
|
- "encoding/hex"
|
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
- "io"
|
|
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
"os"
|
|
"os"
|
|
@@ -75,26 +72,12 @@ func main() {
|
|
saveAllHashFiles()
|
|
saveAllHashFiles()
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log.Printf("file %s has hash %s\n", myFile, getSha256Hash(myFile))
|
|
|
|
|
|
+ log.Printf("file %s has hash %s\n", myFile, hash.GetFileHash(myFile))
|
|
}
|
|
}
|
|
|
|
|
|
log.Println("done")
|
|
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 lock1 = sync.RWMutex{}
|
|
var lock2 = sync.RWMutex{}
|
|
var lock2 = sync.RWMutex{}
|
|
|
|
|
|
@@ -135,7 +118,7 @@ func calculateHash(fileStr string) {
|
|
}
|
|
}
|
|
if doHash {
|
|
if doHash {
|
|
log.Printf("starting %s\n", fileStr)
|
|
log.Printf("starting %s\n", fileStr)
|
|
- hash := getSha256Hash(fileStr)
|
|
|
|
|
|
+ hash := hash.GetFileHash(fileStr)
|
|
log.Printf("ready %s\n", fileStr)
|
|
log.Printf("ready %s\n", fileStr)
|
|
mu.Lock()
|
|
mu.Lock()
|
|
lock1.Lock()
|
|
lock1.Lock()
|