|
@@ -76,6 +76,9 @@ func getSha256Hash(fileStr string) string {
|
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
|
}
|
|
|
|
|
|
+var lock1 = sync.RWMutex{}
|
|
|
+var lock2 = sync.RWMutex{}
|
|
|
+
|
|
|
func outputHash(fileStr string) {
|
|
|
var hashFile Fdhashes
|
|
|
doHash := true
|
|
@@ -97,21 +100,29 @@ func outputHash(fileStr string) {
|
|
|
hashes[dir] = hashFile
|
|
|
saveHashfile(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 {
|
|
|
hash := getSha256Hash(fileStr)
|
|
|
mu.Lock()
|
|
|
+ lock1.Lock()
|
|
|
hashFile.Hashes[fileName] = hash
|
|
|
+ lock1.Unlock()
|
|
|
+ lock2.Lock()
|
|
|
hashFile.Times[fileName] = time
|
|
|
+ lock2.Unlock()
|
|
|
hashes[dir] = hashFile
|
|
|
saveHashfile(hashFile)
|
|
|
mu.Unlock()
|