|
@@ -95,13 +95,13 @@ func outputHash(fileStr string) {
|
|
|
|
|
|
_, ok = hashFile.Hashes[fileName]
|
|
|
doHash = !ok
|
|
|
- hashFile = hashes[dir]
|
|
|
mu.Unlock()
|
|
|
if doHash {
|
|
|
hash := getSha256Hash(fileStr)
|
|
|
mu.Lock()
|
|
|
hashFile.Hashes[fileName] = hash
|
|
|
- saveHashfile(hashFile, dir)
|
|
|
+ hashes[dir] = hashFile
|
|
|
+ saveHashfile(hashFile)
|
|
|
mu.Unlock()
|
|
|
log.Printf("file \"%s\" has hash \"%s\"\n", fileStr, hash)
|
|
|
}
|
|
@@ -148,22 +148,19 @@ func saveHashfile(hashFile Fdhashes, dir string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func loadHashfile(filename string) Fdhashes {
|
|
|
- data := Fdhashes{Hashes: make(map[string]string)}
|
|
|
- if !rewrite {
|
|
|
- file, err := ioutil.ReadFile(filename)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- err = json.Unmarshal([]byte(file), &data)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
+func loadHashfile(fileStr string) Fdhashes {
|
|
|
+ file, err := ioutil.ReadFile(fileStr)
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
}
|
|
|
- data := Fdhashes{}
|
|
|
+ dir, _ := filepath.Split(fileStr)
|
|
|
+ data := Fdhashes{Path: dir, Hashes: make(map[string]string)}
|
|
|
err = json.Unmarshal([]byte(file), &data)
|
|
|
if err != nil {
|
|
|
- log.Fatalf("can't read file %s", filename)
|
|
|
+ log.Printf("can't read file %s", fileStr)
|
|
|
+ }
|
|
|
+ if data.Path == "" {
|
|
|
+ data.Path = dir
|
|
|
}
|
|
|
return data
|
|
|
}
|