From 9d331ce04b000ea1d284ee5b251fbc142ad8f623 Mon Sep 17 00:00:00 2001
From: Nick Craig-Wood <nick@craig-wood.com>
Date: Thu, 5 Jan 2017 17:32:42 +0000
Subject: [PATCH] Implement --ignore-checksum flag

Fixes #793 Fixes #863 Fixes #981
---
 docs/content/docs.md | 9 +++++++++
 fs/config.go         | 3 +++
 fs/operations.go     | 2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/docs/content/docs.md b/docs/content/docs.md
index 459eeb53a..43bedc60f 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -313,6 +313,15 @@ Do a trial run with no permanent changes.  Use this to see what rclone
 would do without actually doing it.  Useful when setting up the `sync`
 command which deletes files in the destination.
 
+### --ignore-checksum ###
+
+Normally rclone will check that the checksums of transferred files
+match, and give an error "corrupted on transfer" if they don't.
+
+You can use this option to skip that check.  You should only use it if
+you have had the "corrupted on transfer" error message and you are
+sure you might want to transfer potentially corrupted data.
+
 ### --ignore-existing ###
 
 Using this option will make rclone unconditionally skip all files
diff --git a/fs/config.go b/fs/config.go
index fbf345571..4231d3126 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -83,6 +83,7 @@ var (
 	noGzip          = BoolP("no-gzip-encoding", "", false, "Don't set Accept-Encoding: gzip.")
 	maxDepth        = IntP("max-depth", "", -1, "If set limits the recursion depth to this.")
 	ignoreSize      = BoolP("ignore-size", "", false, "Ignore size when skipping use mod-time or checksum.")
+	ignoreChecksum  = BoolP("ignore-checksum", "", false, "Skip post copy check of checksums.")
 	noTraverse      = BoolP("no-traverse", "", false, "Don't traverse destination file system on copy.")
 	noUpdateModTime = BoolP("no-update-modtime", "", false, "Don't update destination mod-time if files identical.")
 	backupDir       = StringP("backup-dir", "", "", "Make backups into hierarchy based in DIR.")
@@ -207,6 +208,7 @@ type ConfigInfo struct {
 	NoGzip             bool // Disable compression
 	MaxDepth           int
 	IgnoreSize         bool
+	IgnoreChecksum     bool
 	NoTraverse         bool
 	NoUpdateModTime    bool
 	DataRateUnit       string
@@ -308,6 +310,7 @@ func LoadConfig() {
 	Config.NoGzip = *noGzip
 	Config.MaxDepth = *maxDepth
 	Config.IgnoreSize = *ignoreSize
+	Config.IgnoreChecksum = *ignoreChecksum
 	Config.NoTraverse = *noTraverse
 	Config.NoUpdateModTime = *noUpdateModTime
 	Config.BackupDir = *backupDir
diff --git a/fs/operations.go b/fs/operations.go
index f24f12009..4b0de106e 100644
--- a/fs/operations.go
+++ b/fs/operations.go
@@ -331,7 +331,7 @@ func Copy(f Fs, dst Object, remote string, src Object) (err error) {
 			if err != nil {
 				Stats.Error()
 				ErrorLog(dst, "Failed to read hash: %v", err)
-			} else if !HashEquals(srcSum, dstSum) {
+			} else if !Config.IgnoreSize && !HashEquals(srcSum, dstSum) {
 				Stats.Error()
 				err = errors.Errorf("corrupted on transfer: %v hash differ %q vs %q", hashType, srcSum, dstSum)
 				ErrorLog(dst, "%v", err)