yandex: fix modtime randomly reverting to the upload time after upload

Yandex Disk stores the modtime in a custom property set just after
the upload completes. The server sometimes silently drops this
property (the request returns success but the property is gone when
read back), leaving the object showing the upload time instead.

Check the modtime read back after upload and set it again if it
didn't stick.
This commit is contained in:
Nick Craig-Wood
2026-07-17 18:29:39 +01:00
parent 74d376a7fe
commit ba6ee46d39
+22 -9
View File
@@ -1158,16 +1158,29 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return err
}
//set modTime of uploaded file
err = o.SetModTime(ctx, modTime)
if err != nil {
return err
// Set the modTime of the uploaded file and re-read the metadata
// so the object has the md5sum the server computed for the upload.
//
// The server sometimes silently drops the custom property holding
// the modtime when it is set just after an upload, so check the
// modtime read back and set it again if it didn't stick.
const maxTries = 3
for try := 1; try <= maxTries; try++ {
err = o.SetModTime(ctx, modTime)
if err != nil {
return err
}
o.hasMetaData = false
err = o.readMetaData(ctx)
if err != nil {
return err
}
if o.modTime.Equal(modTime) {
return nil
}
fs.Debugf(o, "modtime not stored after upload (got %v, want %v) - setting again (try %d/%d)", o.modTime, modTime, try, maxTries)
}
// Re-read the metadata so the object has the md5sum the server
// computed for the upload.
o.hasMetaData = false
return o.readMetaData(ctx)
return errors.New("failed to store modtime after upload")
}
// Remove an object