diff --git a/storage/bucket.go b/storage/bucket.go index ee5e4b24f9f2..019a67af68ea 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -1595,6 +1595,23 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle { return &rl } +// Handle ptr or int64 +func getAgeCondition(age interface{}) int64 { + v := reflect.ValueOf(age) + var out int64 = 0 + switch v.Kind() { + case reflect.Int64: + out = v.Interface().(int64) + case reflect.Ptr: + if v.Interface() == nil { + out = 0 + } else { + out = *(v.Interface().(*int64)) + } + } + return out +} + func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { var l Lifecycle if rl == nil { @@ -1607,7 +1624,6 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { StorageClass: rr.Action.StorageClass, }, Condition: LifecycleCondition{ - AgeInDays: rr.Condition.Age, DaysSinceCustomTime: rr.Condition.DaysSinceCustomTime, DaysSinceNoncurrentTime: rr.Condition.DaysSinceNoncurrentTime, MatchesPrefix: rr.Condition.MatchesPrefix, @@ -1616,6 +1632,7 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle { NumNewerVersions: rr.Condition.NumNewerVersions, }, } + r.Condition.AgeInDays = getAgeCondition(rr.Condition.Age) if rr.Condition.IsLive == nil { r.Condition.Liveness = LiveAndArchived