[#2068] blobovnicza: Add Exists
method
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
9eccf3bbf5
commit
6ad2b5d5b8
2 changed files with 38 additions and 1 deletions
29
pkg/local_object_storage/blobovnicza/exists.go
Normal file
29
pkg/local_object_storage/blobovnicza/exists.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package blobovnicza
|
||||
|
||||
import (
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
// Exists check if object with the specified address is stored in b.
|
||||
func (b *Blobovnicza) Exists(addr oid.Address) (bool, error) {
|
||||
var (
|
||||
exists bool
|
||||
addrKey = addressKey(addr)
|
||||
)
|
||||
|
||||
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
||||
return tx.ForEach(func(_ []byte, buck *bbolt.Bucket) error {
|
||||
exists = buck.Get(addrKey) != nil
|
||||
if exists {
|
||||
return errInterruptForEach
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
if err == errInterruptForEach {
|
||||
err = nil
|
||||
}
|
||||
return exists, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue