[#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) { func (t *boltForest) getTreeBuckets(tx *bbolt.Tx, cid cidSDK.ID, treeID string) (*bbolt.Bucket, *bbolt.Bucket, error) {
treeRoot := bucketName(cid, treeID) treeRoot := bucketName(cid, treeID)
child := tx.Bucket(treeRoot)
if child != nil {
return child.Bucket(logBucket), child.Bucket(dataBucket), nil
}
child, err := tx.CreateBucket(treeRoot) child, err := tx.CreateBucket(treeRoot)
if err != nil && err != bbolt.ErrBucketExists { if err != nil {
return nil, nil, err return nil, nil, err
} }
bLog, err := child.CreateBucket(logBucket)
var bLog, bData *bbolt.Bucket if err != nil {
if err == nil { return nil, nil, err
if bLog, err = child.CreateBucket(logBucket); err != nil { }
return nil, nil, err bData, err := child.CreateBucket(dataBucket)
} if err != nil {
if bData, err = child.CreateBucket(dataBucket); err != nil { return nil, nil, err
return nil, nil, err
}
} else {
child = tx.Bucket(treeRoot)
bLog = child.Bucket(logBucket)
bData = child.Bucket(dataBucket)
} }
return bLog, bData, nil return bLog, bData, nil
} }