rclone check: show count of hashes that couldn't be checked #700

This commit is contained in:
Nick Craig-Wood 2016-10-12 10:59:55 +01:00
parent 544ca6035a
commit b7875fc02a

View file

@ -476,28 +476,32 @@ func Overlapping(fdst, fsrc Fs) bool {
// checkIdentical checks to see if dst and src are identical // checkIdentical checks to see if dst and src are identical
// //
// it returns true if differences were found // it returns true if differences were found
func checkIdentical(dst, src Object) bool { // it also returns whether it couldn't be hashed
func checkIdentical(dst, src Object) (bool, bool) {
Stats.Checking(src.Remote()) Stats.Checking(src.Remote())
defer Stats.DoneChecking(src.Remote()) defer Stats.DoneChecking(src.Remote())
if src.Size() != dst.Size() { if src.Size() != dst.Size() {
Stats.Error() Stats.Error()
ErrorLog(src, "Sizes differ") ErrorLog(src, "Sizes differ")
return true return true, false
} }
if !Config.SizeOnly { if !Config.SizeOnly {
same, _, err := CheckHashes(src, dst) same, hash, err := CheckHashes(src, dst)
if err != nil { if err != nil {
// CheckHashes will log and count errors // CheckHashes will log and count errors
return true return true, false
}
if hash == HashNone {
return true, true
} }
if !same { if !same {
Stats.Error() Stats.Error()
ErrorLog(src, "Md5sums differ") ErrorLog(src, "%v differ", hash)
return true return true, false
} }
} }
Debug(src, "OK") Debug(src, "OK")
return false return false, false
} }
// Check the files in fsrc and fdst according to Size and hash // Check the files in fsrc and fdst according to Size and hash
@ -507,6 +511,7 @@ func Check(fdst, fsrc Fs) error {
return err return err
} }
differences := int32(0) differences := int32(0)
noHashes := int32(0)
// FIXME could do this as it goes along and make it use less // FIXME could do this as it goes along and make it use less
// memory. // memory.
@ -550,9 +555,13 @@ func Check(fdst, fsrc Fs) error {
go func() { go func() {
defer checkerWg.Done() defer checkerWg.Done()
for check := range checks { for check := range checks {
if checkIdentical(check[0], check[1]) { differ, noHash := checkIdentical(check[0], check[1])
if differ {
atomic.AddInt32(&differences, 1) atomic.AddInt32(&differences, 1)
} }
if noHash {
atomic.AddInt32(&noHashes, 1)
}
} }
}() }()
} }
@ -560,6 +569,9 @@ func Check(fdst, fsrc Fs) error {
Log(fdst, "Waiting for checks to finish") Log(fdst, "Waiting for checks to finish")
checkerWg.Wait() checkerWg.Wait()
Log(fdst, "%d differences found", Stats.GetErrors()) Log(fdst, "%d differences found", Stats.GetErrors())
if noHashes > 0 {
Log(fdst, "%d hashes could not be checked", noHashes)
}
if differences > 0 { if differences > 0 {
return errors.Errorf("%d differences found", differences) return errors.Errorf("%d differences found", differences)
} }