diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-13 15:04:39 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-15 08:03:53 -0600 |
commit | a2a92e721fcae47d196c5cd45f78f0e69b48278b (patch) | |
tree | 8e97da4d2d9861352842015d954b08b1a94e601f | |
parent | 2c2d616b8650dd01818bd29e11e7b06ae2de5891 (diff) |
btrfsutil: OldRebuiltForrest: Pull the cbs.Item nil check out of the loop
-rw-r--r-- | lib/btrfsutil/old_rebuilt_forrest.go | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go index 6014793..08a204f 100644 --- a/lib/btrfsutil/old_rebuilt_forrest.go +++ b/lib/btrfsutil/old_rebuilt_forrest.go @@ -295,6 +295,9 @@ func (bt *OldRebuiltForrest) TreeWalk(ctx context.Context, treeID btrfsprim.ObjI }) return } + if cbs.Item == nil { + return + } var node *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node] tree.Items.Range(func(indexItem *containers.RBNode[oldRebuiltTreeValue]) bool { if ctx.Err() != nil { @@ -303,23 +306,21 @@ func (bt *OldRebuiltForrest) TreeWalk(ctx context.Context, treeID btrfsprim.ObjI if bt.ctx.Err() != nil { return false } - if cbs.Item != nil { - itemPath := bt.arena.Inflate(indexItem.Value.Path) - if node == nil || node.Addr != itemPath.Node(-2).ToNodeAddr { - var err error + itemPath := bt.arena.Inflate(indexItem.Value.Path) + if node == nil || node.Addr != itemPath.Node(-2).ToNodeAddr { + var err error + btrfstree.FreeNodeRef(node) + node, err = bt.inner.ReadNode(itemPath.Parent()) + if err != nil { btrfstree.FreeNodeRef(node) - node, err = bt.inner.ReadNode(itemPath.Parent()) - if err != nil { - btrfstree.FreeNodeRef(node) - errHandle(&btrfstree.TreeError{Path: itemPath, Err: err}) - return true - } - } - item := node.Data.BodyLeaf[itemPath.Node(-1).FromItemSlot] - if err := cbs.Item(itemPath, item); err != nil { errHandle(&btrfstree.TreeError{Path: itemPath, Err: err}) + return true } } + item := node.Data.BodyLeaf[itemPath.Node(-1).FromItemSlot] + if err := cbs.Item(itemPath, item); err != nil { + errHandle(&btrfstree.TreeError{Path: itemPath, Err: err}) + } return true }) btrfstree.FreeNodeRef(node) |