diff --git a/pkg/local_object_storage/blobstor/delete_big.go b/pkg/local_object_storage/blobstor/delete_big.go index 22599471e..2f51b1d23 100644 --- a/pkg/local_object_storage/blobstor/delete_big.go +++ b/pkg/local_object_storage/blobstor/delete_big.go @@ -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) diff --git a/pkg/local_object_storage/blobstor/exists.go b/pkg/local_object_storage/blobstor/exists.go index b790ac921..c20b21c1c 100644 --- a/pkg/local_object_storage/blobstor/exists.go +++ b/pkg/local_object_storage/blobstor/exists.go @@ -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 }