From 0bea843d9092b946e8611a45bd3b73e0d03f9156 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Thu, 20 Aug 2020 22:41:52 +0300 Subject: [PATCH] Fix DeleteObject handler DeleteObject should remove all objects with passed nice name Signed-off-by: Evgeniy Kulikov --- api/layer/layer.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index 4cf5633b9..2dc95b081 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -371,19 +371,25 @@ func (n *layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*ObjectInf }) } -// DeleteObject from the storage. +// DeleteObject removes all objects with passed nice name. func (n *layer) DeleteObject(ctx context.Context, bucket, object string) error { cid, err := refs.CIDFromString(bucket) if err != nil { return err } - oid, err := n.objectFindID(ctx, cid, object, false) + ids, err := n.objectFindIDs(ctx, cid, object) if err != nil { - return err + return errors.Wrap(err, "could not find object") } - return n.objectDelete(ctx, delParams{addr: refs.Address{CID: cid, ObjectID: oid}}) + 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 nil } // DeleteObjects from the storage.