forked from TrueCloudLab/rclone
core: Verify MD5 sums after each transfer
This commit is contained in:
parent
c4dc9d273a
commit
8a76568ea8
1 changed files with 33 additions and 8 deletions
|
@ -97,6 +97,18 @@ func Equal(src, dst Object) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to remove a failed copy
|
||||||
|
func removeFailedCopy(dst Object) {
|
||||||
|
if dst != nil {
|
||||||
|
Debug(dst, "Removing failed copy")
|
||||||
|
removeErr := dst.Remove()
|
||||||
|
if removeErr != nil {
|
||||||
|
Stats.Error()
|
||||||
|
Log(dst, "Failed to remove failed copy: %s", removeErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copy src object to dst or f if nil
|
// Copy src object to dst or f if nil
|
||||||
//
|
//
|
||||||
// If dst is nil then the object must not exist already. If you do
|
// If dst is nil then the object must not exist already. If you do
|
||||||
|
@ -126,16 +138,29 @@ func Copy(f Fs, dst, src Object) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Stats.Error()
|
Stats.Error()
|
||||||
Log(src, "Failed to copy: %s", err)
|
Log(src, "Failed to copy: %s", err)
|
||||||
if dst != nil {
|
removeFailedCopy(dst)
|
||||||
Debug(dst, "Removing failed copy")
|
|
||||||
removeErr := dst.Remove()
|
|
||||||
if removeErr != nil {
|
|
||||||
Stats.Error()
|
|
||||||
Log(dst, "Failed to remove failed copy: %s", removeErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify md5sums are the same after transfer - ignoring blank md5sums
|
||||||
|
srcMd5sum, md5sumErr := src.Md5sum()
|
||||||
|
if md5sumErr != nil {
|
||||||
|
Stats.Error()
|
||||||
|
Log(src, "Failed to read md5sum: %s", md5sumErr)
|
||||||
|
} else if srcMd5sum != "" {
|
||||||
|
dstMd5sum, md5sumErr := dst.Md5sum()
|
||||||
|
if md5sumErr != nil {
|
||||||
|
Stats.Error()
|
||||||
|
Log(dst, "Failed to read md5sum: %s", md5sumErr)
|
||||||
|
} else if dstMd5sum != "" && srcMd5sum != dstMd5sum {
|
||||||
|
Stats.Error()
|
||||||
|
err = fmt.Errorf("Corrupted on transfer: md5sums differ %q vs %q", srcMd5sum, dstMd5sum)
|
||||||
|
Log(dst, "%s", err)
|
||||||
|
removeFailedCopy(dst)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Debug(src, actionTaken)
|
Debug(src, actionTaken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue