From c387eb8c09b01bb8cdb47d92a789f6ff673a11d5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 9 Oct 2020 16:11:11 +0100 Subject: [PATCH] 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 --- vfs/file.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vfs/file.go b/vfs/file.go index 947f576de..f06b35bb1 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -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 {