From 66744d771525ef537b60d40294f4bb1958135351 Mon Sep 17 00:00:00 2001 From: Tulsishah <46474643+Tulsishah@users.noreply.github.com> Date: Wed, 21 Dec 2022 10:26:02 +0530 Subject: [PATCH] Fixing create object method (#856) * Fixing CreateObject Method * resolving comments * fixing generation condition * 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 24945b33ee..32c16139fb 100644 --- a/internal/storage/bucket_handle.go +++ b/internal/storage/bucket_handle.go @@ -108,14 +108,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}) }