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

Method setMetaData

backend/googlecloudstorage/googlecloudstorage.go:1229–1278  ·  view source on GitHub ↗

setMetaData sets the fs data from a storage.Object

(info *storage.Object)

Source from the content-addressed store, hash-verified

1227
1228// setMetaData sets the fs data from a storage.Object
1229func (o *Object) setMetaData(info *storage.Object) {
1230 o.url = info.MediaLink
1231 o.bytes = int64(info.Size)
1232 o.mimeType = info.ContentType
1233 o.gzipped = info.ContentEncoding == "gzip"
1234
1235 // Read md5sum
1236 md5sumData, err := base64.StdEncoding.DecodeString(info.Md5Hash)
1237 if err != nil {
1238 fs.Logf(o, "Bad MD5 decode: %v", err)
1239 } else {
1240 o.md5sum = hex.EncodeToString(md5sumData)
1241 }
1242
1243 // read mtime out of metadata if available
1244 mtimeString, ok := info.Metadata[metaMtime]
1245 if ok {
1246 modTime, err := time.Parse(timeFormat, mtimeString)
1247 if err == nil {
1248 o.modTime = modTime
1249 return
1250 }
1251 fs.Debugf(o, "Failed to read mtime from metadata: %s", err)
1252 }
1253
1254 // Fallback to GSUtil mtime
1255 mtimeGsutilString, ok := info.Metadata[metaMtimeGsutil]
1256 if ok {
1257 unixTimeSec, err := strconv.ParseInt(mtimeGsutilString, 10, 64)
1258 if err == nil {
1259 o.modTime = time.Unix(unixTimeSec, 0)
1260 return
1261 }
1262 fs.Debugf(o, "Failed to read GSUtil mtime from metadata: %s", err)
1263 }
1264
1265 // Fallback to the Updated time
1266 modTime, err := time.Parse(timeFormat, info.Updated)
1267 if err != nil {
1268 fs.Logf(o, "Bad time decode: %v", err)
1269 } else {
1270 o.modTime = modTime
1271 }
1272
1273 // If gunzipping then size and md5sum are unknown
1274 if o.gzipped && o.fs.opt.Decompress {
1275 o.bytes = -1
1276 o.md5sum = ""
1277 }
1278}
1279
1280// readObjectInfo reads the definition for an object
1281func (o *Object) readObjectInfo(ctx context.Context) (object *storage.Object, err error) {

Callers 5

newObjectWithInfoMethod · 0.95
CopyMethod · 0.95
readMetaDataMethod · 0.95
SetModTimeMethod · 0.95
UpdateMethod · 0.95

Calls 4

LogfFunction · 0.92
DebugfFunction · 0.92
DecodeStringMethod · 0.65
EncodeToStringMethod · 0.65

Tested by

no test coverage detected