2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExistsPrm groups the parameters of Exists operation.
|
|
|
|
type ExistsPrm struct {
|
2022-01-26 12:11:13 +00:00
|
|
|
addr *addressSDK.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExistsRes groups resulting values of Exists operation.
|
|
|
|
type ExistsRes struct {
|
|
|
|
ex bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAddress is an Exists option to set object checked for existence.
|
2022-01-26 12:11:13 +00:00
|
|
|
func (p *ExistsPrm) WithAddress(addr *addressSDK.Address) *ExistsPrm {
|
2020-11-17 12:23:15 +00:00
|
|
|
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.
|
2022-03-17 08:03:58 +00:00
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been marked as removed.
|
2020-11-17 12:23:15 +00:00
|
|
|
func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) {
|
2020-11-18 14:38:49 +00:00
|
|
|
exists, err := s.objectExists(prm.addr)
|
|
|
|
|
2020-11-17 12:23:15 +00:00
|
|
|
return &ExistsRes{
|
2020-11-18 14:38:49 +00:00
|
|
|
ex: exists,
|
2020-12-01 08:35:44 +00:00
|
|
|
}, err
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
2020-11-18 14:38:49 +00:00
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (s *Shard) objectExists(addr *addressSDK.Address) (bool, error) {
|
2020-12-08 09:56:14 +00:00
|
|
|
return meta.Exists(s.metaBase, addr)
|
2020-11-18 14:38:49 +00:00
|
|
|
}
|