[#1621] pilorama: Simplify bucket creation

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-22 09:31:24 +03:00 committed by Anton Nikiforov
parent fe7ddfdc6a
commit e9ba8931f8

View file

@ -273,25 +273,23 @@ func (t *boltForest) TreeApply(d CIDDescriptor, treeID string, m *Move) error {
func (t *boltForest) getTreeBuckets(tx *bbolt.Tx, cid cidSDK.ID, treeID string) (*bbolt.Bucket, *bbolt.Bucket, error) {
treeRoot := bucketName(cid, treeID)
child := tx.Bucket(treeRoot)
if child != nil {
return child.Bucket(logBucket), child.Bucket(dataBucket), nil
}
child, err := tx.CreateBucket(treeRoot)
if err != nil && err != bbolt.ErrBucketExists {
if err != nil {
return nil, nil, err
}
var bLog, bData *bbolt.Bucket
if err == nil {
if bLog, err = child.CreateBucket(logBucket); err != nil {
bLog, err := child.CreateBucket(logBucket)
if err != nil {
return nil, nil, err
}
if bData, err = child.CreateBucket(dataBucket); err != nil {
bData, err := child.CreateBucket(dataBucket)
if err != nil {
return nil, nil, err
}
} else {
child = tx.Bucket(treeRoot)
bLog = child.Bucket(logBucket)
bData = child.Bucket(dataBucket)
}
return bLog, bData, nil
}