From e319f2422e98129f8ae019493e440420b3da2ea2 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Fri, 1 Apr 2022 15:48:05 +0400 Subject: [PATCH] [#357] Remove checks of bucket settings is not nil Via #389 Also fixed test Signed-off-by: Angira Kekteeva --- api/handler/multipart_upload.go | 2 +- api/layer/layer.go | 10 ++-------- api/layer/versioning_test.go | 3 +-- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index 5de58159..018f55ef 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -457,7 +457,7 @@ func (h *handler) CompleteMultipartUploadHandler(w http.ResponseWriter, r *http. Key: objInfo.Name, } - if bktSettings != nil && bktSettings.VersioningEnabled { + if bktSettings.VersioningEnabled { w.Header().Set(api.AmzVersionID, objInfo.Version()) } diff --git a/api/layer/layer.go b/api/layer/layer.go index 3842ae5d..f3b30740 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -547,14 +547,8 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings var ( err error ids []*oid.ID - - versioningEnabled = false ) - if settings != nil { - versioningEnabled = settings.VersioningEnabled - } - p := &PutObjectParams{ BktInfo: bkt, Object: obj.Name, @@ -565,7 +559,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings // Current implementation doesn't consider "unversioned" mode (so any deletion creates "delete-mark" object). // The reason is difficulties to determinate whether versioning mode is "unversioned" or "suspended". - if obj.VersionID == unversionedObjectVersionID || !versioningEnabled && len(obj.VersionID) == 0 { + if obj.VersionID == unversionedObjectVersionID || !settings.VersioningEnabled && len(obj.VersionID) == 0 { p.Header[versionsUnversionedAttr] = "true" versions, err := n.headVersions(ctx, bkt, obj.Name) if err != nil { @@ -618,7 +612,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings } if len(obj.VersionID) == 0 { obj.DeleteMarkVersion = objInfo.Version() - if versioningEnabled { + if settings.VersioningEnabled { obj.DeleteMarkerEtag = objInfo.HashSum } } diff --git a/api/layer/versioning_test.go b/api/layer/versioning_test.go index ca44572f..1487169c 100644 --- a/api/layer/versioning_test.go +++ b/api/layer/versioning_test.go @@ -10,7 +10,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api/data" - "github.com/nspcc-dev/neofs-s3-gw/api/errors" "github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" "github.com/nspcc-dev/neofs-s3-gw/internal/neofstest" @@ -360,7 +359,7 @@ func TestNoVersioningDeleteObject(t *testing.T) { tc.putObject([]byte("content obj1 v2")) versioning, err := tc.layer.GetBucketSettings(tc.ctx, tc.bktInfo) - require.Error(t, err, errors.GetAPIError(errors.ErrNoSuchKey)) + require.NoError(t, err) tc.deleteObject(tc.obj, "", versioning) tc.getObject(tc.obj, "", true)