summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-02 13:00:59 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-02 13:00:59 -0600
commit249500e0b88aea7ce77fa0720a207f303e6ceabf (patch)
tree27591416132abb9c808b58f927c513a3ee4e2d7a /pkg
parent9c581316735f78c4fec9787aa4fd8635398b4c51 (diff)
multi error
Diffstat (limited to 'pkg')
-rw-r--r--pkg/btrfs/btree.go22
-rw-r--r--pkg/btrfs/io2_fs.go13
2 files changed, 24 insertions, 11 deletions
diff --git a/pkg/btrfs/btree.go b/pkg/btrfs/btree.go
index 9f38eee..cc68002 100644
--- a/pkg/btrfs/btree.go
+++ b/pkg/btrfs/btree.go
@@ -8,6 +8,8 @@ import (
"math"
"strings"
+ "github.com/datawire/dlib/derror"
+
"lukeshu.com/btrfs-tools/pkg/util"
)
@@ -386,6 +388,10 @@ func (fs *FS) TreeLookup(treeRoot LogicalAddr, key Key) (Item, error) {
return fs.TreeSearch(treeRoot, key.Cmp)
}
+// If some items are able to be read, but there is an error reading the full set, then it might
+// return *both* a list of items and an error.
+//
+// If no such item is found, an error that is io/fs.ErrNotExist is returned.
func (fs *FS) TreeSearchAll(treeRoot LogicalAddr, fn func(Key) int) ([]Item, error) {
middlePath, middleNode, err := fs.treeSearch(treeRoot, fn)
if err != nil {
@@ -394,12 +400,12 @@ func (fs *FS) TreeSearchAll(treeRoot LogicalAddr, fn func(Key) int) ([]Item, err
middleItem := middleNode.Data.BodyLeaf[middlePath[len(middlePath)-1].ItemIdx]
var ret = []Item{middleItem}
- i := 0
+ var errs derror.MultiError
for prevPath, prevNode := middlePath, middleNode; true; {
- i--
prevPath, prevNode, err = fs.prev(prevPath, prevNode)
if err != nil {
- return nil, err
+ errs = append(errs, err)
+ break
}
if prevPath == nil {
break
@@ -411,12 +417,11 @@ func (fs *FS) TreeSearchAll(treeRoot LogicalAddr, fn func(Key) int) ([]Item, err
ret = append(ret, prevItem)
}
util.ReverseSlice(ret)
- i = 0
for nextPath, nextNode := middlePath, middleNode; true; {
- i++
nextPath, nextNode, err = fs.next(nextPath, nextNode)
if err != nil {
- return nil, err
+ errs = append(errs, err)
+ break
}
if nextPath == nil {
break
@@ -427,5 +432,8 @@ func (fs *FS) TreeSearchAll(treeRoot LogicalAddr, fn func(Key) int) ([]Item, err
}
ret = append(ret, nextItem)
}
- return ret, nil
+ if errs != nil {
+ err = errs
+ }
+ return ret, err
}
diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go
index 33bfcbf..5129329 100644
--- a/pkg/btrfs/io2_fs.go
+++ b/pkg/btrfs/io2_fs.go
@@ -4,6 +4,8 @@ import (
"fmt"
"io"
+ "github.com/datawire/dlib/derror"
+
"lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem"
"lukeshu.com/btrfs-tools/pkg/btrfs/btrfsvol"
"lukeshu.com/btrfs-tools/pkg/util"
@@ -169,13 +171,16 @@ func (fs *FS) initDev(sb *util.Ref[PhysicalAddr, Superblock]) error {
}
func (fs *FS) Close() error {
- var err error
+ var errs derror.MultiError
for _, dev := range fs.LV.PhysicalVolumes() {
- if _err := dev.Close(); _err != nil && err == nil {
- err = _err
+ if err := dev.Close(); err != nil && err == nil {
+ errs = append(errs, err)
}
}
- return err
+ if errs != nil {
+ return errs
+ }
+ return nil
}
var _ io.Closer = (*FS)(nil)