From b937174402feb9c41fb8ab14641e5abfa3ce2037 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 18 Nov 2022 06:50:33 +0000 Subject: [PATCH 1/4] Fixing CreateObject Method --- internal/storage/bucket_handle.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/internal/storage/bucket_handle.go b/internal/storage/bucket_handle.go index bd7c8acce7..8228e3a44e 100644 --- a/internal/storage/bucket_handle.go +++ b/internal/storage/bucket_handle.go @@ -112,20 +112,13 @@ func (bh *bucketHandle) CreateObject(ctx context.Context, req *gcs.CreateObjectR // GenerationPrecondition - If non-nil, the object will be created/overwritten // only if the current generation for the object name is equal to the given value. // Zero means the object does not exist. - if req.GenerationPrecondition != nil { + if req.GenerationPrecondition != nil && *req.GenerationPrecondition != 0 { obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition}) } - // MetagenerationMatch - Similar work as GenerationPrecondition, but it is only - // meaningful in conjunction with GenerationPrecondition. Here, it will take - // the object with the latest generation. - if req.MetaGenerationPrecondition != nil { - obj = obj.If(storage.Conditions{MetagenerationMatch: *req.MetaGenerationPrecondition}) - } - // Operation will depend on both generation and meta-generation precondition. - if req.GenerationPrecondition != nil && req.MetaGenerationPrecondition != nil { - obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition, MetagenerationMatch: *req.MetaGenerationPrecondition}) + if req.MetaGenerationPrecondition != nil && *req.MetaGenerationPrecondition != 0 { + obj = obj.If(storage.Conditions{MetagenerationMatch: *req.MetaGenerationPrecondition}) } // Creating a NewWriter with requested attributes, using Go Storage Client. From 34ed6f1c53d1593b076583e70c328200ac16bb31 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Mon, 21 Nov 2022 04:35:19 +0000 Subject: [PATCH 2/4] resolving comments --- internal/storage/bucket_handle.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/storage/bucket_handle.go b/internal/storage/bucket_handle.go index 8228e3a44e..fcc16f0761 100644 --- a/internal/storage/bucket_handle.go +++ b/internal/storage/bucket_handle.go @@ -116,7 +116,9 @@ func (bh *bucketHandle) CreateObject(ctx context.Context, req *gcs.CreateObjectR obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition}) } - // Operation will depend on both generation and meta-generation precondition. + // MetaGenerationPrecondition - If non-nil, the object will be created/overwritten + // only if the current metaGeneration for the object name is equal to the given value. + // Zero means the object does not exist. if req.MetaGenerationPrecondition != nil && *req.MetaGenerationPrecondition != 0 { obj = obj.If(storage.Conditions{MetagenerationMatch: *req.MetaGenerationPrecondition}) } From ccc77efe2d892da9f298a886ae33fbca6cbaf2a6 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Tue, 29 Nov 2022 11:07:00 +0000 Subject: [PATCH 3/4] fixing generation condition --- internal/storage/bucket_handle.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/storage/bucket_handle.go b/internal/storage/bucket_handle.go index fcc16f0761..c9bfb5113f 100644 --- a/internal/storage/bucket_handle.go +++ b/internal/storage/bucket_handle.go @@ -112,14 +112,14 @@ func (bh *bucketHandle) CreateObject(ctx context.Context, req *gcs.CreateObjectR // GenerationPrecondition - If non-nil, the object will be created/overwritten // only if the current generation for the object name is equal to the given value. // Zero means the object does not exist. - if req.GenerationPrecondition != nil && *req.GenerationPrecondition != 0 { - obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition}) - } - // MetaGenerationPrecondition - If non-nil, the object will be created/overwritten // only if the current metaGeneration for the object name is equal to the given value. // Zero means the object does not exist. - if req.MetaGenerationPrecondition != nil && *req.MetaGenerationPrecondition != 0 { + if req.GenerationPrecondition != nil && *req.GenerationPrecondition != 0 && req.MetaGenerationPrecondition != nil && *req.MetaGenerationPrecondition != 0 { + obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition, MetagenerationMatch: *req.MetaGenerationPrecondition}) + } else if req.GenerationPrecondition != nil && *req.GenerationPrecondition != 0 { + obj = obj.If(storage.Conditions{GenerationMatch: *req.GenerationPrecondition}) + } else if req.MetaGenerationPrecondition != nil && *req.MetaGenerationPrecondition != 0 { obj = obj.If(storage.Conditions{MetagenerationMatch: *req.MetaGenerationPrecondition}) } From 51b39d64dd743b860af230da19100406a0ee8172 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Tue, 29 Nov 2022 11:13:32 +0000 Subject: [PATCH 4/4] fixing generation condition --- internal/storage/bucket_handle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/storage/bucket_handle.go b/internal/storage/bucket_handle.go index ab7b584576..72935fcd6a 100644 --- a/internal/storage/bucket_handle.go +++ b/internal/storage/bucket_handle.go @@ -43,8 +43,8 @@ func (bh *bucketHandle) Name() string { } func (bh *bucketHandle) NewReader( - ctx context.Context, - req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { + ctx context.Context, + req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { // Initialising the starting offset and the length to be read by the reader. start := int64(0) length := int64(-1)