[#211] blobstor: Implement Exists method
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
1ba556f5e7
commit
59f7cf9873
2 changed files with 54 additions and 5 deletions
|
@ -34,10 +34,9 @@ func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fsTree) delete(addr *object.Address) error {
|
func (t *fsTree) delete(addr *object.Address) error {
|
||||||
p := t.treePath(addr)
|
p, err := t.exists(addr)
|
||||||
|
if err != nil {
|
||||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
return err
|
||||||
return errFileNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.Remove(p)
|
return os.Remove(p)
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package blobstor
|
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.
|
// ExistsPrm groups the parameters of Exists operation.
|
||||||
type ExistsPrm struct {
|
type ExistsPrm struct {
|
||||||
address
|
address
|
||||||
|
@ -20,5 +28,47 @@ func (r ExistsRes) Exists() bool {
|
||||||
// Returns any error encountered that did not allow
|
// Returns any error encountered that did not allow
|
||||||
// to completely check object existence.
|
// to completely check object existence.
|
||||||
func (b *BlobStor) Exists(prm *ExistsPrm) (*ExistsRes, error) {
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue