Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Implement --no-update-modtime flag - fixes #511

Nick Craig-Woodb9479cf7ab5b
diff --git a/docs/content/docs.md b/docs/content/docs.md
index 66ae96819..4930b5bed 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -560,6 +560,14 @@ uploaded compressed files.
There is no need to set this in normal operation, and doing so will
decrease the network transfer efficiency of rclone.
+### --no-update-modtime ###
+
+When using this flag, rclone won't update modification times of remote
+files if they are incorrect as it would normally.
+
+This can be used if the remote is being synced with another tool also
+(eg the Google Drive client).
+
### -q, --quiet ###
Normally rclone outputs stats and a completion message. If you set
diff --git a/fs/config.go b/fs/config.go
index ba26a6de6..2f01046ce 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -89,6 +89,7 @@ var (
maxDepth = pflag.IntP("max-depth", "", -1, "If set limits the recursion depth to this.")
ignoreSize = pflag.BoolP("ignore-size", "", false, "Ignore size when skipping use mod-time or checksum.")
noTraverse = pflag.BoolP("no-traverse", "", false, "Don't traverse destination file system on copy.")
+ noUpdateModTime = pflag.BoolP("no-update-modtime", "", false, "Don't update destination mod-time if files identical.")
bwLimit SizeSuffix
// Key to use for password en/decryption.
@@ -240,6 +241,7 @@ type ConfigInfo struct {
MaxDepth int
IgnoreSize bool
NoTraverse bool
+ NoUpdateModTime bool
}
// Transport returns an http.RoundTripper with the correct timeouts
@@ -345,6 +347,7 @@ func LoadConfig() {
Config.MaxDepth = *maxDepth
Config.IgnoreSize = *ignoreSize
Config.NoTraverse = *noTraverse
+ Config.NoUpdateModTime = *noUpdateModTime
ConfigPath = *configFile
diff --git a/fs/operations.go b/fs/operations.go
index 5a247ed02..b759e2c35 100644
--- a/fs/operations.go
+++ b/fs/operations.go
@@ -147,7 +147,7 @@ func Equal(src, dst Object) bool {
return false
}
- if !Config.CheckSum {
+ if !(Config.CheckSum || Config.NoUpdateModTime) {
// Size and hash the same but mtime different so update the
// mtime of the dst object here
err := dst.SetModTime(srcModTime)
diff --git a/fs/sync_test.go b/fs/sync_test.go
index 853b1c743..b0d7e2180 100644
--- a/fs/sync_test.go
+++ b/fs/sync_test.go
@@ -311,6 +311,25 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {
fstest.CheckItems(t, r.fremote, file1)
}
+func TestSyncAfterChangingModtimeOnlyWithNoUpdateModTime(t *testing.T) {
+ r := NewRun(t)
+ defer r.Finalise()
+ fs.Config.NoUpdateModTime = true
+ defer func() {
+ fs.Config.NoUpdateModTime = false
+ }()
+
+ file1 := r.WriteFile("empty space", "", t2)
+ file2 := r.WriteObject("empty space", "", t1)
+
+ fs.Stats.ResetCounters()
+ err := fs.Sync(r.fremote, r.flocal)
+ require.NoError(t, err)
+
+ fstest.CheckItems(t, r.flocal, file1)
+ fstest.CheckItems(t, r.fremote, file2)
+}
+
func TestSyncAfterAddingAFile(t *testing.T) {
r := NewRun(t)
defer r.Finalise()