vfs: don't set modification time if it was already correct

Before this change, rclone would set the modification time of an
object after it had been uploaded. However with --vfs-cache-mode
writes and above, the modification time of the object is already
correct as the cache backing file gets set with the correct
modification time before upload.

Setting the modification time causes another version to be created on
backends such as S3 so it should be avoided if possible.

This change checks to see if the modification time needs changing and
only sets it if necessary.

See: https://forum.rclone.org/t/produce-2-versions-when-overwrite-an-object-in-min-io/19634
This commit is contained in:
Nick Craig-Wood 2020-10-09 16:11:11 +01:00
parent a12b2746b4
commit c387eb8c09

View File

@ -382,6 +382,13 @@ func (f *File) _applyPendingModTime() error {
return errors.New("Cannot apply ModTime, file object is not available")
}
dt := f.pendingModTime.Sub(f.o.ModTime(context.Background()))
modifyWindow := f.o.Fs().Precision()
if dt < modifyWindow && dt > -modifyWindow {
fs.Debugf(f.o, "Not setting pending mod time %v as it is already set", f.pendingModTime)
return nil
}
// set the time of the object
err := f.o.SetModTime(context.TODO(), f.pendingModTime)
switch err {