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

This commit is contained in:
Nick Craig-Wood 2016-07-12 10:46:45 +01:00
parent 452a5badc1
commit b9479cf7ab
4 changed files with 31 additions and 1 deletions

View file

@ -560,6 +560,14 @@ uploaded compressed files.
There is no need to set this in normal operation, and doing so will There is no need to set this in normal operation, and doing so will
decrease the network transfer efficiency of rclone. 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 ### ### -q, --quiet ###
Normally rclone outputs stats and a completion message. If you set Normally rclone outputs stats and a completion message. If you set

View file

@ -89,6 +89,7 @@ var (
maxDepth = pflag.IntP("max-depth", "", -1, "If set limits the recursion depth to this.") 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.") 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.") 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 bwLimit SizeSuffix
// Key to use for password en/decryption. // Key to use for password en/decryption.
@ -240,6 +241,7 @@ type ConfigInfo struct {
MaxDepth int MaxDepth int
IgnoreSize bool IgnoreSize bool
NoTraverse bool NoTraverse bool
NoUpdateModTime bool
} }
// Transport returns an http.RoundTripper with the correct timeouts // Transport returns an http.RoundTripper with the correct timeouts
@ -345,6 +347,7 @@ func LoadConfig() {
Config.MaxDepth = *maxDepth Config.MaxDepth = *maxDepth
Config.IgnoreSize = *ignoreSize Config.IgnoreSize = *ignoreSize
Config.NoTraverse = *noTraverse Config.NoTraverse = *noTraverse
Config.NoUpdateModTime = *noUpdateModTime
ConfigPath = *configFile ConfigPath = *configFile

View file

@ -147,7 +147,7 @@ func Equal(src, dst Object) bool {
return false return false
} }
if !Config.CheckSum { if !(Config.CheckSum || Config.NoUpdateModTime) {
// Size and hash the same but mtime different so update the // Size and hash the same but mtime different so update the
// mtime of the dst object here // mtime of the dst object here
err := dst.SetModTime(srcModTime) err := dst.SetModTime(srcModTime)

View file

@ -311,6 +311,25 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {
fstest.CheckItems(t, r.fremote, file1) 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) { func TestSyncAfterAddingAFile(t *testing.T) {
r := NewRun(t) r := NewRun(t)
defer r.Finalise() defer r.Finalise()