From 796bba3793654a48f2c8ff0d9fd5a156cbb1c86a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 18 Nov 2020 17:38:49 +0300 Subject: [PATCH] [#176] shard: Finalize the implementation of Exists method Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/exists.go | 13 +++++++++++-- pkg/local_object_storage/shard/put.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 9fa5e73a1..9a25763a6 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -2,6 +2,7 @@ package shard import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/pkg/errors" ) // ExistsPrm groups the parameters of Exists operation. @@ -33,8 +34,16 @@ func (p *ExistsRes) Exists() bool { // Returns any error encountered that does not allow to // unambiguously determine the presence of an object. func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) { - // FIXME: implement me + exists, err := s.objectExists(prm.addr) + if err != nil { + return nil, errors.Wrap(err, "could not check object presence in metabase") + } + return &ExistsRes{ - ex: false, + ex: exists, }, nil } + +func (s *Shard) objectExists(addr *object.Address) (bool, error) { + return s.metaBase.Exists(addr) +} diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index 411581dc3..29c74f8bc 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -29,7 +29,7 @@ func (p *PutPrm) WithObject(obj *object.Object) *PutPrm { // did not allow to completely save the object. func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { // check object existence - ex, err := s.metaBase.Exists(prm.obj.Address()) + ex, err := s.objectExists(prm.obj.Address()) if err != nil { return nil, errors.Wrap(err, "could not check object existence") } else if ex {