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

azurefiles: fix incorrect modtime after uploading a file or setting its modtime

Nick Craig-Wood397c0f872a37
diff --git a/backend/azurefiles/azurefiles.go b/backend/azurefiles/azurefiles.go
index ba49e7850..db0b9262a 100644
--- a/backend/azurefiles/azurefiles.go
+++ b/backend/azurefiles/azurefiles.go
@@ -58,6 +58,9 @@ const (
maxFileSize = 4 * fs.Tebi
defaultChunkSize = 4 * fs.Mebi
storageDefaultBaseURL = "file.core.windows.net"
+ // smbTimePrecision is the precision the server stores
+ // modtimes with (100 ns FILETIME ticks)
+ smbTimePrecision = 100 * time.Nanosecond
)
func init() {
@@ -598,7 +601,10 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) error {
if err != nil {
return fmt.Errorf("unable to set modTime: %w", err)
}
- o.modTime = t
+ // Truncate to the precision the server stores the modtime with
+ // to keep the in-memory modtime identical to the one a fresh
+ // listing returns.
+ o.modTime = t.Truncate(smbTimePrecision)
return nil
}
@@ -769,10 +775,12 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return fmt.Errorf("update: failed to set properties: %w", err)
}
- // Make sure Object is in sync
+ // Make sure Object is in sync, truncating the modtime to the
+ // precision the server stores it with so it is identical to the
+ // one a fresh listing returns
o.size = size
o.md5 = md5Hash
- o.modTime = modTime
+ o.modTime = modTime.Truncate(smbTimePrecision)
o.contentType = contentType
return nil
}