Reduce number of logs and show hash type where appropriate
This commit is contained in:
parent
109d4ee490
commit
cd62f41606
1 changed files with 22 additions and 18 deletions
|
@ -45,38 +45,42 @@ func HashEquals(src, dst string) bool {
|
||||||
// CheckHashes checks the two files to see if they have common
|
// CheckHashes checks the two files to see if they have common
|
||||||
// known hash types and compares them
|
// known hash types and compares them
|
||||||
//
|
//
|
||||||
// Returns two bools, the first of which is equality and the second of
|
// Returns
|
||||||
// which is true if either of the hashes were unset.
|
|
||||||
//
|
//
|
||||||
// May return an error which will already have been logged
|
// equal - which is equality of the hashes
|
||||||
|
//
|
||||||
|
// hash - the HashType. This is HashNone if either of the hashes were
|
||||||
|
// unset or a compatible hash couldn't be found.
|
||||||
|
//
|
||||||
|
// err - may return an error which will already have been logged
|
||||||
//
|
//
|
||||||
// If an error is returned it will return equal as false
|
// If an error is returned it will return equal as false
|
||||||
func CheckHashes(src, dst Object) (equal bool, unset bool, err error) {
|
func CheckHashes(src, dst Object) (equal bool, hash HashType, err error) {
|
||||||
common := src.Fs().Hashes().Overlap(dst.Fs().Hashes())
|
common := src.Fs().Hashes().Overlap(dst.Fs().Hashes())
|
||||||
Debug(nil, "Shared hashes: %v", common)
|
// Debug(nil, "Shared hashes: %v", common)
|
||||||
if common.Count() == 0 {
|
if common.Count() == 0 {
|
||||||
return true, true, nil
|
return true, HashNone, nil
|
||||||
}
|
}
|
||||||
usehash := common.GetOne()
|
hash = common.GetOne()
|
||||||
srcHash, err := src.Hash(usehash)
|
srcHash, err := src.Hash(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Stats.Error()
|
Stats.Error()
|
||||||
ErrorLog(src, "Failed to calculate src hash: %s", err)
|
ErrorLog(src, "Failed to calculate src hash: %s", err)
|
||||||
return false, false, err
|
return false, hash, err
|
||||||
}
|
}
|
||||||
if srcHash == "" {
|
if srcHash == "" {
|
||||||
return true, true, nil
|
return true, HashNone, nil
|
||||||
}
|
}
|
||||||
dstHash, err := dst.Hash(usehash)
|
dstHash, err := dst.Hash(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Stats.Error()
|
Stats.Error()
|
||||||
ErrorLog(dst, "Failed to calculate dst hash: %s", err)
|
ErrorLog(dst, "Failed to calculate dst hash: %s", err)
|
||||||
return false, false, err
|
return false, hash, err
|
||||||
}
|
}
|
||||||
if dstHash == "" {
|
if dstHash == "" {
|
||||||
return true, true, nil
|
return true, HashNone, nil
|
||||||
}
|
}
|
||||||
return srcHash == dstHash, false, nil
|
return srcHash == dstHash, hash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal checks to see if the src and dst objects are equal by looking at
|
// Equal checks to see if the src and dst objects are equal by looking at
|
||||||
|
@ -127,7 +131,7 @@ func Equal(src, dst Object) bool {
|
||||||
|
|
||||||
// mtime is unreadable or different but size is the same so
|
// mtime is unreadable or different but size is the same so
|
||||||
// check the hash
|
// check the hash
|
||||||
same, hashunset, _ := CheckHashes(src, dst)
|
same, hash, _ := CheckHashes(src, dst)
|
||||||
if !same {
|
if !same {
|
||||||
Debug(src, "Hash differ")
|
Debug(src, "Hash differ")
|
||||||
return false
|
return false
|
||||||
|
@ -139,10 +143,10 @@ func Equal(src, dst Object) bool {
|
||||||
dst.SetModTime(srcModTime)
|
dst.SetModTime(srcModTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hashunset {
|
if hash == HashNone {
|
||||||
Debug(src, "Size of src and dst objects identical")
|
Debug(src, "Size of src and dst objects identical")
|
||||||
} else {
|
} else {
|
||||||
Debug(src, "Size and hash of src and dst objects identical")
|
Debug(src, "Size and %v of src and dst objects identical", hash)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -255,7 +259,7 @@ tryAgain:
|
||||||
// TODO(klauspost): This could be extended, so we always create a hash type matching
|
// TODO(klauspost): This could be extended, so we always create a hash type matching
|
||||||
// the destination, and calculate it while sending.
|
// the destination, and calculate it while sending.
|
||||||
common := src.Fs().Hashes().Overlap(dst.Fs().Hashes())
|
common := src.Fs().Hashes().Overlap(dst.Fs().Hashes())
|
||||||
Debug(src, "common hashes: %v", common)
|
// Debug(src, "common hashes: %v", common)
|
||||||
if !Config.SizeOnly && common.Count() > 0 {
|
if !Config.SizeOnly && common.Count() > 0 {
|
||||||
// Get common hash type
|
// Get common hash type
|
||||||
hashType := common.GetOne()
|
hashType := common.GetOne()
|
||||||
|
|
Loading…
Add table
Reference in a new issue