filescom: fix missing MD5 hash after uploading a file
The server computes the MD5 checksum asynchronously after upload, so the object returned from Put and Update often had no MD5 while a fresh listing shortly afterwards would report one. This broke wrappers which compare exact hashes, such as the hasher backend's fingerprint and the VFS cache. Retry reading the metadata for a short time after upload until the MD5 appears.
This commit is contained in:
@@ -866,7 +866,24 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
return err
|
||||
}
|
||||
|
||||
return o.readMetaData(ctx)
|
||||
// The server computes the MD5 asynchronously after upload so
|
||||
// retry reading the metadata for a short time until it appears.
|
||||
const maxTries = 10
|
||||
for tries := 1; ; tries++ {
|
||||
err = o.readMetaData(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if o.md5 != "" || tries >= maxTries {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(time.Duration(tries) * 100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove an object
|
||||
|
||||
Reference in New Issue
Block a user