Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

s3: try to keep the maximum precision in ModTime with --user-server-modtime

Nick Craig-Woodcf0bf159abbf
diff --git a/backend/s3/s3.go b/backend/s3/s3.go
index 6abfd541c..9aba03a3f 100644
--- a/backend/s3/s3.go
+++ b/backend/s3/s3.go
@@ -4507,7 +4507,15 @@ func (o *Object) setMetaData(resp *s3.HeadObjectOutput) {
o.lastModified = time.Now()
fs.Logf(o, "Failed to read last modified")
} else {
- o.lastModified = *resp.LastModified
+ // Try to keep the maximum precision in lastModified. If we read
+ // it from listings then it may have millisecond precision, but
+ // if we read it from a HEAD/GET request then it will have
+ // second precision.
+ equalToWithinOneSecond := o.lastModified.Truncate(time.Second).Equal((*resp.LastModified).Truncate(time.Second))
+ newHasNs := (*resp.LastModified).Nanosecond() != 0
+ if !equalToWithinOneSecond || newHasNs {
+ o.lastModified = *resp.LastModified
+ }
}
o.mimeType = aws.StringValue(resp.ContentType)