operations: implement --refresh-times flag to set modtimes on hashless backends

This commit is contained in:
Nick Craig-Wood 2020-06-16 16:24:54 +01:00
parent d174b97af7
commit 3efdf5e095
4 changed files with 38 additions and 1 deletions

View File

@ -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).

View File

@ -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

View File

@ -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

View File

@ -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
}