[#211] blobstor: Implement Exists method

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-25 14:18:54 +03:00 committed by Alex Vanin
parent 1ba556f5e7
commit 59f7cf9873
2 changed files with 54 additions and 5 deletions

View file

@ -34,10 +34,9 @@ func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) {
}
func (t *fsTree) delete(addr *object.Address) error {
p := t.treePath(addr)
if _, err := os.Stat(p); os.IsNotExist(err) {
return errFileNotFound
p, err := t.exists(addr)
if err != nil {
return err
}
return os.Remove(p)

View file

@ -1,5 +1,13 @@
package blobstor
import (
"os"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/pkg/errors"
)
// ExistsPrm groups the parameters of Exists operation.
type ExistsPrm struct {
address
@ -20,5 +28,47 @@ func (r ExistsRes) Exists() bool {
// Returns any error encountered that did not allow
// to completely check object existence.
func (b *BlobStor) Exists(prm *ExistsPrm) (*ExistsRes, error) {
panic("implement me")
// check presence in shallow dir first (cheaper)
exists, err := b.existsBig(prm.addr)
if !exists {
// TODO: do smth if err != nil
// check presence in blobovnicza
exists, err = b.existsSmall(prm.addr)
}
if err != nil {
return nil, err
}
return &ExistsRes{
exists: exists,
}, err
}
// checks if object is presented in shallow dir.
func (b *BlobStor) existsBig(addr *object.Address) (bool, error) {
_, err := b.fsTree.exists(addr)
if errors.Is(err, errFileNotFound) {
return false, nil
}
return err == nil, err
}
// checks if object is presented in blobovnicza.
func (b *BlobStor) existsSmall(addr *object.Address) (bool, error) {
// TODO: implement
return false, nil
}
func (t *fsTree) exists(addr *objectSDK.Address) (string, error) {
p := t.treePath(addr)
_, err := os.Stat(p)
if os.IsNotExist(err) {
err = errFileNotFound
}
return p, err
}