2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-18 14:38:49 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExistsPrm groups the parameters of Exists operation.
|
|
|
|
type ExistsPrm struct {
|
|
|
|
addr *object.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExistsRes groups resulting values of Exists operation.
|
|
|
|
type ExistsRes struct {
|
|
|
|
ex bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAddress is an Exists option to set object checked for existence.
|
|
|
|
func (p *ExistsPrm) WithAddress(addr *object.Address) *ExistsPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exists returns the fact that the object is in the shard.
|
|
|
|
func (p *ExistsRes) Exists() bool {
|
|
|
|
return p.ex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exists checks if object is presented in shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that does not allow to
|
|
|
|
// unambiguously determine the presence of an object.
|
|
|
|
func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) {
|
2020-11-18 14:38:49 +00:00
|
|
|
exists, err := s.objectExists(prm.addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not check object presence in metabase")
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:23:15 +00:00
|
|
|
return &ExistsRes{
|
2020-11-18 14:38:49 +00:00
|
|
|
ex: exists,
|
2020-11-17 12:23:15 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2020-11-18 14:38:49 +00:00
|
|
|
|
|
|
|
func (s *Shard) objectExists(addr *object.Address) (bool, error) {
|
|
|
|
return s.metaBase.Exists(addr)
|
|
|
|
}
|