From 960aa02bd3fd5ebf4715c06503e7ea771412ba30 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Sat, 22 Aug 2020 05:41:58 +0300 Subject: [PATCH] Refactoring DeleteObject/DeleteObjects methods - methods should return api.DeleteErrors - DeleteObjects should return only slice of errors - don't add nil errors Signed-off-by: Evgeniy Kulikov --- api/layer/layer.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index 2dc95b081..77379826f 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -12,8 +12,9 @@ import ( "github.com/nspcc-dev/neofs-api-go/service" "github.com/nspcc-dev/neofs-s3-gate/api" "github.com/nspcc-dev/neofs-s3-gate/api/pool" - "github.com/pkg/errors" "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) type ( @@ -375,17 +376,26 @@ func (n *layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*ObjectInf func (n *layer) DeleteObject(ctx context.Context, bucket, object string) error { cid, err := refs.CIDFromString(bucket) if err != nil { - return err + return &api.DeleteError{ + Err: err, + Object: object, + } } ids, err := n.objectFindIDs(ctx, cid, object) if err != nil { - return errors.Wrap(err, "could not find object") + return &api.DeleteError{ + Err: err, + Object: object, + } } for _, id := range ids { if err = n.objectDelete(ctx, delParams{addr: refs.Address{CID: cid, ObjectID: id}}); err != nil { - return errors.Wrapf(err, "could not remove object: %s => %s", object, id) + return &api.DeleteError{ + Err: err, + Object: object, + } } } @@ -393,12 +403,14 @@ func (n *layer) DeleteObject(ctx context.Context, bucket, object string) error { } // DeleteObjects from the storage. -func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []string) ([]error, error) { +func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []string) []error { var errs = make([]error, 0, len(objects)) for i := range objects { - errs = append(errs, n.DeleteObject(ctx, bucket, objects[i])) + if err := n.DeleteObject(ctx, bucket, objects[i]); err != nil { + errs = append(errs, err) + } } - return errs, nil + return errs }