From 4402e37a0eaa14ba29a4a75f21e91cd3c59d9ebd Mon Sep 17 00:00:00 2001 From: KastenMike <93532247+KastenMike@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:14:15 +0200 Subject: [PATCH] dont break interface --- repo/blob/gcs/gcs_storage.go | 24 ++++++++++++++++++------ repo/blob/gcs/gcs_versioned.go | 6 +----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/repo/blob/gcs/gcs_storage.go b/repo/blob/gcs/gcs_storage.go index 93b564e62a5..b58700fc576 100644 --- a/repo/blob/gcs/gcs_storage.go +++ b/repo/blob/gcs/gcs_storage.go @@ -75,14 +75,26 @@ func (gcs *gcsStorage) getBlobWithVersion(ctx context.Context, b blob.ID, versio return blob.EnsureLengthExactly(output.Length(), length) } -func (gcs *gcsStorage) GetMetadata(oi *storage.ObjectAttrs) blob.Metadata { +func (gcs *gcsStorage) GetMetadata(ctx context.Context, b blob.ID) (blob.Metadata, error) { + objName := gcs.getObjectNameString(b) + obj := gcs.bucket.Object(objName) + + attrs, err := obj.Attrs(ctx) + if err != nil { + return blob.Metadata{}, errors.Wrap(translateError(err), "Attrs") + } + + return gcs.getBlobMeta(attrs), nil +} + +func (gcs *gcsStorage) getBlobMeta(attrs *storage.ObjectAttrs) blob.Metadata { bm := blob.Metadata{ - BlobID: toBlobID(oi.Name, gcs.Prefix), - Length: oi.Size, - Timestamp: oi.Created, + BlobID: toBlobID(attrs.Name, gcs.Prefix), + Length: attrs.Size, + Timestamp: attrs.Created, } - if t, ok := timestampmeta.FromValue(oi.Metadata[timeMapKey]); ok { + if t, ok := timestampmeta.FromValue(attrs.Metadata[timeMapKey]); ok { bm.Timestamp = t } return bm @@ -203,7 +215,7 @@ func (gcs *gcsStorage) ListBlobs(ctx context.Context, prefix blob.ID, callback f oa, err := lst.Next() for err == nil { - bm := gcs.GetMetadata(oa) + bm := gcs.getBlobMeta(oa) if cberr := callback(bm); cberr != nil { return cberr diff --git a/repo/blob/gcs/gcs_versioned.go b/repo/blob/gcs/gcs_versioned.go index 546e3190502..065bd0e2dae 100644 --- a/repo/blob/gcs/gcs_versioned.go +++ b/repo/blob/gcs/gcs_versioned.go @@ -95,11 +95,7 @@ func toBlobID(blobName, prefix string) blob.ID { } func (gcs *gcsPointInTimeStorage) getVersionMetadata(prefix string, oi *storage.ObjectAttrs) versionMetadata { - bm := blob.Metadata{ - BlobID: toBlobID(oi.Name, prefix), - Length: oi.Size, - Timestamp: oi.Created, - } + bm := gcs.getBlobMeta(oi) return versionMetadata{ Metadata: bm, IsDeleteMarker: !oi.Deleted.IsZero() && (gcs.PointInTime == nil || oi.Deleted.Before(*gcs.PointInTime)),