diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 18:44:26 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 22:42:08 -0700 |
commit | de9874d67f8a5b4bd934137c82d7010b58dfe004 (patch) | |
tree | c76f9b2dff67d5bc56df2b456249593b63d66b70 /lib/btrfs/csums.go | |
parent | 493ec396fab32d9e8859e34ad497fdb0a910a33c (diff) |
tree-wide: Audit for simplistic type assertions
Diffstat (limited to 'lib/btrfs/csums.go')
-rw-r--r-- | lib/btrfs/csums.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/btrfs/csums.go b/lib/btrfs/csums.go index bbd19bd..a32f090 100644 --- a/lib/btrfs/csums.go +++ b/lib/btrfs/csums.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> // // SPDX-License-Identifier: GPL-2.0-or-later @@ -56,9 +56,15 @@ func LookupCSum(fs btrfstree.TreeOperator, alg btrfssum.CSumType, laddr btrfsvol if err != nil { return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, err } - body, ok := item.Body.(btrfsitem.ExtentCSum) - if !ok { - return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, fmt.Errorf("item body is %T not ExtentCSum", item.Body) + if item.Key.ItemType != btrfsitem.EXTENT_CSUM_KEY { + return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, fmt.Errorf("item type is %v, not EXTENT_CSUM", item.Key.ItemType) + } + switch body := item.Body.(type) { + case btrfsitem.ExtentCSum: + return body.SumRun, nil + case btrfsitem.Error: + return btrfssum.SumRun[btrfsvol.LogicalAddr]{}, body.Err + default: + panic(fmt.Errorf("should not happen: EXTENT_CSUM has unexpected item type: %T", body)) } - return body.SumRun, nil } |