From 3efdf5e0952950dbc1312506cb7da297ba21f9be Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 16 Jun 2020 16:24:54 +0100 Subject: [PATCH] operations: implement --refresh-times flag to set modtimes on hashless backends --- docs/content/docs.md | 35 ++++++++++++++++++++++++++++ fs/config.go | 1 + fs/config/configflags/configflags.go | 1 + fs/operations/operations.go | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/content/docs.md b/docs/content/docs.md index aa6d154d4..0351dfd62 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -1096,6 +1096,41 @@ is fixed all non-ASCII characters will be replaced with `.` when This flag will limit rclone's output to error messages only. +### --refresh-times ### + +The `--refresh-times` flag can be used to update modification times of +existing files when they are out of sync on backends which don't +support hashes. + +This is useful if you uploaded files with the incorrect timestamps and +you now wish to correct them. + +This flag is **only** useful for destinations which don't support +hashes (eg `crypt`). + +This can be used any of the sync commands `sync`, `copy` or `move`. + +To use this flag you will need to be doing a modification time sync +(so not using `--size-only` or `--checksum`). The flag will have no +effect when using `--size-only` or `--checksum`. + +If this flag is used when rclone comes to upload a file it will check +to see if there is an existing file on the destination. If this file +matches the source with size (and checksum if available) but has a +differing timestamp then instead of re-uploading it, rclone will +update the timestamp on the destination file. If the checksum does not +match rclone will upload the new file. If the checksum is absent (eg +on a `crypt` backend) then rclone will update the timestamp. + +Note that some remotes can't set the modification time without +re-uploading the file so this flag is less useful on them. + +Normally if you are doing a modification time sync rclone will update +modification times without `--refresh-times` provided that the remote +supports checksums **and** the checksums match on the file. However if the +checksums are absent then rclone will upload the file rather than +setting the timestamp as this is the safe behaviour. + ### --retries int ### Retry the entire sync if it fails this many times it fails (default 3). diff --git a/fs/config.go b/fs/config.go index df22bced4..0ba74fc75 100644 --- a/fs/config.go +++ b/fs/config.go @@ -117,6 +117,7 @@ type ConfigInfo struct { UploadHeaders []*HTTPOption DownloadHeaders []*HTTPOption Headers []*HTTPOption + RefreshTimes bool } // NewConfig creates a new config with everything set to the default diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.go index 9d2120919..084b98fb7 100644 --- a/fs/config/configflags/configflags.go +++ b/fs/config/configflags/configflags.go @@ -121,6 +121,7 @@ func AddFlags(flagSet *pflag.FlagSet) { flags.StringArrayVarP(flagSet, &uploadHeaders, "header-upload", "", nil, "Set HTTP header for upload transactions") flags.StringArrayVarP(flagSet, &downloadHeaders, "header-download", "", nil, "Set HTTP header for download transactions") flags.StringArrayVarP(flagSet, &headers, "header", "", nil, "Set HTTP header for all transactions") + flags.BoolVarP(flagSet, &fs.Config.RefreshTimes, "refresh-times", "", fs.Config.RefreshTimes, "Refresh the modtime of remote files.") } // ParseHeaders converts the strings passed in via the header flags into HTTPOptions diff --git a/fs/operations/operations.go b/fs/operations/operations.go index be15eff69..18f238947 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -207,7 +207,7 @@ func equal(ctx context.Context, src fs.ObjectInfo, dst fs.Object, opt equalOpt) fs.Debugf(src, "%v differ", ht) return false } - if ht == hash.None { + if ht == hash.None && !fs.Config.RefreshTimes { // if couldn't check hash, return that they differ return false }