From e0b8bc6cd6702fb9747914e974ae531dcdcf67f2 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 9 Mar 2022 13:23:33 +0300 Subject: [PATCH] [#195] Fix object deletion Signed-off-by: Denis Kirillov --- api/handler/delete.go | 5 +++++ api/layer/layer.go | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api/handler/delete.go b/api/handler/delete.go index 281bbd11..493e4b5a 100644 --- a/api/handler/delete.go +++ b/api/handler/delete.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "net/http" "strconv" + "strings" "github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api/errors" @@ -70,6 +71,10 @@ func (h *handler) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) { err = deletedObject.Error } if err != nil { + if strings.Contains(err.Error(), "object is locked") { + h.logAndSendError(w, "object is locked", reqInfo, errors.GetAPIError(errors.ErrAccessDenied)) + return + } h.log.Error("could not delete object", zap.String("request_id", reqInfo.RequestID), zap.String("bucket_name", reqInfo.BucketName), diff --git a/api/layer/layer.go b/api/layer/layer.go index 44c0602a..00347654 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -310,6 +310,8 @@ func (n *layer) handleLockTick(ctx context.Context, msg *nats.Msg) error { return fmt.Errorf("invalid msg, address expected: %w", err) } + n.log.Debug("handling lock tick", zap.String("address", string(msg.Data))) + // todo clear cache // and make sure having right access return n.objectDelete(ctx, addr.ContainerID(), addr.ObjectID()) @@ -646,15 +648,6 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, obj *Ver p.Header[VersionsDeleteMarkAttr] = DelMarkFullObject } - objInfo, err := n.objectPut(ctx, bkt, p) - if err != nil { - obj.Error = err - return obj - } - if len(obj.VersionID) == 0 { - obj.DeleteMarkVersion = objInfo.Version() - } - for _, id := range ids { if err = n.objectDelete(ctx, bkt.CID, id); err != nil { obj.Error = err @@ -667,6 +660,15 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, obj *Ver } n.listsCache.CleanCacheEntriesContainingObject(obj.Name, bkt.CID) + objInfo, err := n.objectPut(ctx, bkt, p) + if err != nil { + obj.Error = err + return obj + } + if len(obj.VersionID) == 0 { + obj.DeleteMarkVersion = objInfo.Version() + } + return obj }