[#357] Remove checks of bucket settings is not nil

Via #389
Also fixed test

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-04-01 15:48:05 +04:00 committed by Alex Vanin
parent 02bcbe9754
commit e319f2422e
3 changed files with 4 additions and 11 deletions

View file

@ -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())
}

View file

@ -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
}
}

View file

@ -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)