Fix DeleteObject handler

DeleteObject should remove all objects with passed nice name

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-08-20 22:41:52 +03:00
parent 34f6eb7d55
commit 0bea843d90

View file

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