From ba6ee46d39a9ef962b69d534915a2f43c56d03cd Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 17 Jul 2026 08:46:04 +0100 Subject: [PATCH] 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. --- backend/yandex/yandex.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/yandex/yandex.go b/backend/yandex/yandex.go index e2b7da877..beff566b9 100644 --- a/backend/yandex/yandex.go +++ b/backend/yandex/yandex.go @@ -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