2020-10-28 14:49:30 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get returns object header for specified address.
|
|
|
|
func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) {
|
|
|
|
var obj *object.Object
|
|
|
|
|
|
|
|
if err := db.boltDB.View(func(tx *bbolt.Tx) error {
|
2020-10-29 12:03:55 +00:00
|
|
|
addrKey := addressKey(addr)
|
|
|
|
|
|
|
|
// check if object marked as deleted
|
|
|
|
if objectRemoved(tx, addrKey) {
|
2020-11-30 16:39:05 +00:00
|
|
|
return object.ErrNotFound
|
2020-10-29 12:03:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 14:49:30 +00:00
|
|
|
primaryBucket := tx.Bucket(primaryBucket)
|
|
|
|
if primaryBucket == nil {
|
2020-11-30 16:39:05 +00:00
|
|
|
return object.ErrNotFound
|
2020-10-28 14:49:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 12:03:55 +00:00
|
|
|
data := primaryBucket.Get(addrKey)
|
2020-10-28 14:49:30 +00:00
|
|
|
if data == nil {
|
2020-11-30 16:39:05 +00:00
|
|
|
return object.ErrNotFound
|
2020-10-28 14:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
obj = object.New()
|
|
|
|
|
|
|
|
err = obj.Unmarshal(data)
|
2020-10-28 14:49:30 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj, nil
|
|
|
|
}
|