MCPcopy
hub / github.com/rclone/rclone / setMetaData

Method setMetaData

backend/s3/s3.go:4044–4104  ·  view source on GitHub ↗
(resp *s3.HeadObjectOutput)

Source from the content-addressed store, hash-verified

4042}
4043
4044func (o *Object) setMetaData(resp *s3.HeadObjectOutput) {
4045 // Ignore missing Content-Length assuming it is 0
4046 // Some versions of ceph do this due their apache proxies
4047 if resp.ContentLength != nil {
4048 o.bytes = *resp.ContentLength
4049 }
4050 o.setMD5FromEtag(deref(resp.ETag))
4051 o.meta = s3MetadataToMap(resp.Metadata)
4052 // Read MD5 from metadata if present
4053 if md5sumBase64, ok := o.meta[metaMD5Hash]; ok {
4054 md5sumBytes, err := base64.StdEncoding.DecodeString(md5sumBase64)
4055 if err != nil {
4056 fs.Debugf(o, "Failed to read md5sum from metadata %q: %v", md5sumBase64, err)
4057 } else if len(md5sumBytes) != 16 {
4058 fs.Debugf(o, "Failed to read md5sum from metadata %q: wrong length", md5sumBase64)
4059 } else {
4060 o.md5 = hex.EncodeToString(md5sumBytes)
4061 }
4062 }
4063 if resp.LastModified == nil {
4064 o.lastModified = time.Now()
4065 fs.Logf(o, "Failed to read last modified")
4066 } else {
4067 // Try to keep the maximum precision in lastModified. If we read
4068 // it from listings then it may have millisecond precision, but
4069 // if we read it from a HEAD/GET request then it will have
4070 // second precision.
4071 equalToWithinOneSecond := o.lastModified.Truncate(time.Second).Equal(resp.LastModified.Truncate(time.Second))
4072 newHasNs := resp.LastModified.Nanosecond() != 0
4073 if !equalToWithinOneSecond || newHasNs {
4074 o.lastModified = *resp.LastModified
4075 }
4076 }
4077 o.mimeType = strings.Clone(deref(resp.ContentType))
4078
4079 // Set system metadata
4080 o.storageClass = stringClone(string(resp.StorageClass))
4081 o.cacheControl = stringClonePointer(resp.CacheControl)
4082 o.contentDisposition = stringClonePointer(resp.ContentDisposition)
4083 o.contentEncoding = stringClonePointer(removeAWSChunked(resp.ContentEncoding))
4084 o.contentLanguage = stringClonePointer(resp.ContentLanguage)
4085
4086 // Set Object Lock metadata
4087 if resp.ObjectLockMode != "" {
4088 mode := string(resp.ObjectLockMode)
4089 o.objectLockMode = &mode
4090 }
4091 if resp.ObjectLockRetainUntilDate != nil {
4092 o.objectLockRetainUntilDate = resp.ObjectLockRetainUntilDate
4093 }
4094 if resp.ObjectLockLegalHoldStatus != "" {
4095 status := string(resp.ObjectLockLegalHoldStatus)
4096 o.objectLockLegalHoldStatus = &status
4097 }
4098
4099 // If decompressing then size and md5sum are unknown
4100 if o.fs.opt.Decompress && deref(o.contentEncoding) == "gzip" {
4101 o.bytes = -1

Callers 4

readMetaDataMethod · 0.95
downloadFromURLMethod · 0.95
OpenMethod · 0.95
UpdateMethod · 0.95

Calls 12

setMD5FromEtagMethod · 0.95
DebugfFunction · 0.92
LogfFunction · 0.92
derefFunction · 0.85
s3MetadataToMapFunction · 0.85
stringCloneFunction · 0.85
stringClonePointerFunction · 0.85
removeAWSChunkedFunction · 0.85
DecodeStringMethod · 0.65
EncodeToStringMethod · 0.65
TruncateMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected