summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 19:33:03 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 22:42:08 -0700
commita06a7fb2d5bbf1ca5659de06fc9e975666bdcf9f (patch)
tree268aaa2725e4ad336412118779377177601c662b
parentc307e7048da3c02e1e540eab227def7fec7340cc (diff)
lint: Turn on gofumpt
All edits to .go files are made by `tools/bin/golangci-lint run --fix ./...`, not by me as a human.
-rw-r--r--.golangci.yml1
-rw-r--r--lib/binstruct/binint/builtins.go12
-rw-r--r--lib/btrfs/btrfsitem/items.go1
-rw-r--r--lib/btrfs/btrfssum/csum_test.go1
-rw-r--r--lib/btrfs/btrfstree/ops.go2
-rw-r--r--lib/btrfs/btrfstree/types_node.go14
-rw-r--r--lib/btrfs/btrfsvol/lvm.go3
-rw-r--r--lib/btrfs/io2_lv.go1
-rw-r--r--lib/btrfs/io3_btree.go3
-rw-r--r--lib/btrfs/io4_fs.go1
-rw-r--r--lib/btrfsprogs/btrfsinspect/mount.go10
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go2
-rw-r--r--lib/containers/lru.go7
-rw-r--r--lib/containers/syncmap.go5
-rw-r--r--lib/fmtutil/fmt.go3
-rw-r--r--lib/textui/text.go4
16 files changed, 54 insertions, 16 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 953b512..edb8499 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -35,7 +35,6 @@ linters:
- godot
- godox
- goerr113
- - gofumpt
- gomnd
- gomoddirectives
- ireturn
diff --git a/lib/binstruct/binint/builtins.go b/lib/binstruct/binint/builtins.go
index 01186bc..e4be2a6 100644
--- a/lib/binstruct/binint/builtins.go
+++ b/lib/binstruct/binint/builtins.go
@@ -34,6 +34,7 @@ func (x U16le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint16(buf[:], uint16(x))
return buf[:], nil
}
+
func (x *U16le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 2); err != nil {
return 0, err
@@ -50,6 +51,7 @@ func (x U32le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint32(buf[:], uint32(x))
return buf[:], nil
}
+
func (x *U32le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 4); err != nil {
return 0, err
@@ -66,6 +68,7 @@ func (x U64le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint64(buf[:], uint64(x))
return buf[:], nil
}
+
func (x *U64le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 8); err != nil {
return 0, err
@@ -84,6 +87,7 @@ func (x U16be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint16(buf[:], uint16(x))
return buf[:], nil
}
+
func (x *U16be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 2); err != nil {
return 0, err
@@ -100,6 +104,7 @@ func (x U32be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint32(buf[:], uint32(x))
return buf[:], nil
}
+
func (x *U32be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 4); err != nil {
return 0, err
@@ -116,6 +121,7 @@ func (x U64be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint64(buf[:], uint64(x))
return buf[:], nil
}
+
func (x *U64be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 8); err != nil {
return 0, err
@@ -148,6 +154,7 @@ func (x I16le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint16(buf[:], uint16(x))
return buf[:], nil
}
+
func (x *I16le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 2); err != nil {
return 0, err
@@ -164,6 +171,7 @@ func (x I32le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint32(buf[:], uint32(x))
return buf[:], nil
}
+
func (x *I32le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 4); err != nil {
return 0, err
@@ -180,6 +188,7 @@ func (x I64le) MarshalBinary() ([]byte, error) {
binary.LittleEndian.PutUint64(buf[:], uint64(x))
return buf[:], nil
}
+
func (x *I64le) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 8); err != nil {
return 0, err
@@ -198,6 +207,7 @@ func (x I16be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint16(buf[:], uint16(x))
return buf[:], nil
}
+
func (x *I16be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 2); err != nil {
return 0, err
@@ -214,6 +224,7 @@ func (x I32be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint32(buf[:], uint32(x))
return buf[:], nil
}
+
func (x *I32be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 4); err != nil {
return 0, err
@@ -230,6 +241,7 @@ func (x I64be) MarshalBinary() ([]byte, error) {
binary.BigEndian.PutUint64(buf[:], uint64(x))
return buf[:], nil
}
+
func (x *I64be) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 8); err != nil {
return 0, err
diff --git a/lib/btrfs/btrfsitem/items.go b/lib/btrfs/btrfsitem/items.go
index d300179..67f96fa 100644
--- a/lib/btrfs/btrfsitem/items.go
+++ b/lib/btrfs/btrfsitem/items.go
@@ -70,7 +70,6 @@ func UnmarshalItem(key btrfsprim.Key, csumType btrfssum.CSumType, dat []byte) It
Dat: dat,
Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): %w", key.ItemType, err),
}
-
}
if n < len(dat) {
return Error{
diff --git a/lib/btrfs/btrfssum/csum_test.go b/lib/btrfs/btrfssum/csum_test.go
index 5c17779..0a4aef6 100644
--- a/lib/btrfs/btrfssum/csum_test.go
+++ b/lib/btrfs/btrfssum/csum_test.go
@@ -22,7 +22,6 @@ func TestCSumFormat(t *testing.T) {
}
csum := btrfssum.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
testcases := map[string]TestCase{
-
"s": {InputSum: csum, InputFmt: "%s", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"},
"x": {InputSum: csum, InputFmt: "%x", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"},
"v": {InputSum: csum, InputFmt: "%v", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"},
diff --git a/lib/btrfs/btrfstree/ops.go b/lib/btrfs/btrfstree/ops.go
index ddab630..537773a 100644
--- a/lib/btrfs/btrfstree/ops.go
+++ b/lib/btrfs/btrfstree/ops.go
@@ -504,7 +504,7 @@ func (fs TreeOperatorImpl) TreeSearchAll(treeID btrfsprim.ObjID, fn func(btrfspr
}
middleItem := middleNode.Data.BodyLeaf[middlePath.Node(-1).FromItemIdx]
- var ret = []Item{middleItem}
+ ret := []Item{middleItem}
var errs derror.MultiError
for prevPath, prevNode := middlePath, middleNode; true; {
prevPath, prevNode, err = fs.prev(prevPath, prevNode)
diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go
index d2e91de..b709d34 100644
--- a/lib/btrfs/btrfstree/types_node.go
+++ b/lib/btrfs/btrfstree/types_node.go
@@ -26,11 +26,13 @@ type NodeFlags uint64
func (NodeFlags) BinaryStaticSize() int {
return 7
}
+
func (f NodeFlags) MarshalBinary() ([]byte, error) {
var bs [8]byte
binary.LittleEndian.PutUint64(bs[:], uint64(f))
return bs[:7], nil
}
+
func (f *NodeFlags) UnmarshalBinary(dat []byte) (int, error) {
var bs [8]byte
copy(bs[:7], dat[:7])
@@ -418,9 +420,11 @@ func (e *IOError) Unwrap() error { return e.Err }
// NodeError are ErrNotANode and *IOError.
func ReadNode[Addr ~int64](fs diskio.File[Addr], sb Superblock, addr Addr, exp NodeExpectations) (*diskio.Ref[Addr, Node], error) {
if int(sb.NodeSize) < binstruct.StaticSize(NodeHeader{}) {
- return nil, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr,
+ return nil, &NodeError[Addr]{
+ Op: "btrfstree.ReadNode", NodeAddr: addr,
Err: fmt.Errorf("superblock.NodeSize=%v is too small to contain even a node header (%v bytes)",
- sb.NodeSize, binstruct.StaticSize(NodeHeader{}))}
+ sb.NodeSize, binstruct.StaticSize(NodeHeader{})),
+ }
}
nodeBuf := make([]byte, sb.NodeSize)
if _, err := fs.ReadAt(nodeBuf, addr); err != nil {
@@ -456,9 +460,11 @@ func ReadNode[Addr ~int64](fs diskio.File[Addr], sb Superblock, addr Addr, exp N
return nodeRef, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr, Err: err}
}
if stored != calced {
- return nodeRef, &NodeError[Addr]{Op: "btrfstree.ReadNode", NodeAddr: addr,
+ return nodeRef, &NodeError[Addr]{
+ Op: "btrfstree.ReadNode", NodeAddr: addr,
Err: fmt.Errorf("looks like a node but is corrupt: checksum mismatch: stored=%v calculated=%v",
- stored, calced)}
+ stored, calced),
+ }
}
// parse (main)
diff --git a/lib/btrfs/btrfsvol/lvm.go b/lib/btrfs/btrfsvol/lvm.go
index 605524b..1cb1ded 100644
--- a/lib/btrfs/btrfsvol/lvm.go
+++ b/lib/btrfs/btrfsvol/lvm.go
@@ -82,6 +82,7 @@ func (lv *LogicalVolume[PhysicalVolume]) Close() error {
}
return nil
}
+
func (lv *LogicalVolume[PhysicalVolume]) AddPhysicalVolume(id DeviceID, dev PhysicalVolume) error {
lv.init()
if other, exists := lv.id2pv[id]; exists {
@@ -121,9 +122,11 @@ type Mapping struct {
func (lv *LogicalVolume[PhysicalVolume]) CouldAddMapping(m Mapping) bool {
return lv.addMapping(m, true) == nil
}
+
func (lv *LogicalVolume[PhysicalVolume]) AddMapping(m Mapping) error {
return lv.addMapping(m, false)
}
+
func (lv *LogicalVolume[PhysicalVolume]) addMapping(m Mapping, dryRun bool) error {
lv.init()
// sanity check
diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go
index 3f82cd0..ac7ea70 100644
--- a/lib/btrfs/io2_lv.go
+++ b/lib/btrfs/io2_lv.go
@@ -70,6 +70,7 @@ func (fs *FS) Size() btrfsvol.LogicalAddr {
func (fs *FS) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error) {
return fs.LV.ReadAt(p, off)
}
+
func (fs *FS) WriteAt(p []byte, off btrfsvol.LogicalAddr) (int, error) {
return fs.LV.WriteAt(p, off)
}
diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go
index b8c1a6d..8ec4b41 100644
--- a/lib/btrfs/io3_btree.go
+++ b/lib/btrfs/io3_btree.go
@@ -17,12 +17,15 @@ import (
func (fs *FS) TreeWalk(ctx context.Context, treeID btrfsprim.ObjID, errHandle func(*btrfstree.TreeError), cbs btrfstree.TreeWalkHandler) {
btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeWalk(ctx, treeID, errHandle, cbs)
}
+
func (fs *FS) TreeLookup(treeID btrfsprim.ObjID, key btrfsprim.Key) (btrfstree.Item, error) {
return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeLookup(treeID, key)
}
+
func (fs *FS) TreeSearch(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) (btrfstree.Item, error) {
return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearch(treeID, fn)
}
+
func (fs *FS) TreeSearchAll(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) ([]btrfstree.Item, error) {
return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearchAll(treeID, fn)
}
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index d9c7cdb..3848ef1 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -95,7 +95,6 @@ func (sv *Subvolume) init() {
default:
panic(fmt.Errorf("should not happen: ROOT_ITEM has unexpected item type: %T", rootBody))
}
-
})
}
diff --git a/lib/btrfsprogs/btrfsinspect/mount.go b/lib/btrfsprogs/btrfsinspect/mount.go
index 29193cb..f061526 100644
--- a/lib/btrfsprogs/btrfsinspect/mount.go
+++ b/lib/btrfsprogs/btrfsinspect/mount.go
@@ -144,11 +144,11 @@ func inodeItemToFUSE(itemBody btrfsitem.Inode) fuseops.InodeAttributes {
Size: uint64(itemBody.Size),
Nlink: uint32(itemBody.NLink),
Mode: uint32(itemBody.Mode),
- //RDev: itemBody.Rdev, // jacobsa/fuse doesn't expose rdev
+ // RDev: itemBody.Rdev, // jacobsa/fuse doesn't expose rdev
Atime: itemBody.ATime.ToStd(),
Mtime: itemBody.MTime.ToStd(),
Ctime: itemBody.CTime.ToStd(),
- //Crtime: itemBody.OTime,
+ // Crtime: itemBody.OTime,
Uid: uint32(itemBody.UID),
Gid: uint32(itemBody.GID),
}
@@ -260,7 +260,7 @@ func (sv *subvolume) LookUpInode(_ context.Context, op *fuseops.LookUpInodeOp) e
Child: 2, // an inode number that a real file will never have
Attributes: fuseops.InodeAttributes{
Nlink: 1,
- Mode: uint32(btrfsitem.ModeFmtDir | 0700),
+ Mode: uint32(btrfsitem.ModeFmtDir | 0o700),
},
}
return nil
@@ -315,6 +315,7 @@ func (sv *subvolume) OpenDir(_ context.Context, op *fuseops.OpenDirOp) error {
op.Handle = handle
return nil
}
+
func (sv *subvolume) ReadDir(_ context.Context, op *fuseops.ReadDirOp) error {
state, ok := sv.dirHandles.Load(op.Handle)
if !ok {
@@ -348,6 +349,7 @@ func (sv *subvolume) ReadDir(_ context.Context, op *fuseops.ReadDirOp) error {
}
return nil
}
+
func (sv *subvolume) ReleaseDirHandle(_ context.Context, op *fuseops.ReleaseDirHandleOp) error {
_, ok := sv.dirHandles.LoadAndDelete(op.Handle)
if !ok {
@@ -369,6 +371,7 @@ func (sv *subvolume) OpenFile(_ context.Context, op *fuseops.OpenFileOp) error {
op.KeepPageCache = true
return nil
}
+
func (sv *subvolume) ReadFile(_ context.Context, op *fuseops.ReadFileOp) error {
state, ok := sv.fileHandles.Load(op.Handle)
if !ok {
@@ -392,6 +395,7 @@ func (sv *subvolume) ReadFile(_ context.Context, op *fuseops.ReadFileOp) error {
return err
}
+
func (sv *subvolume) ReleaseFileHandle(_ context.Context, op *fuseops.ReleaseFileHandleOp) error {
_, ok := sv.fileHandles.LoadAndDelete(op.Handle)
if !ok {
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go
index 3057e75..5d0804c 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go
@@ -386,6 +386,7 @@ func (o *rebuilder) want(ctx context.Context, reason string, treeID btrfsprim.Ob
fmt.Sprintf("tree=%v key={%v %v ?}", treeID, objID, typ))
o._want(ctx, treeID, objID, typ)
}
+
func (o *rebuilder) _want(ctx context.Context, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType) (key btrfsprim.Key, ok bool) {
if !o.rebuilt.AddTree(ctx, treeID) {
o.itemQueue = append(o.itemQueue, o.curKey)
@@ -429,6 +430,7 @@ func (o *rebuilder) wantOff(ctx context.Context, reason string, treeID btrfsprim
ctx = dlog.WithField(ctx, "btrfsinspect.rebuild-nodes.rebuild.want.key", keyAndTree{TreeID: treeID, Key: key})
o._wantOff(ctx, treeID, key)
}
+
func (o *rebuilder) _wantOff(ctx context.Context, treeID btrfsprim.ObjID, tgt btrfsprim.Key) (ok bool) {
if !o.rebuilt.AddTree(ctx, treeID) {
o.itemQueue = append(o.itemQueue, o.curKey)
diff --git a/lib/containers/lru.go b/lib/containers/lru.go
index 12446b0..bfda361 100644
--- a/lib/containers/lru.go
+++ b/lib/containers/lru.go
@@ -36,10 +36,12 @@ func (c *LRUCache[K, V]) Add(key K, value V) {
c.init()
c.inner.Add(key, value)
}
+
func (c *LRUCache[K, V]) Contains(key K) bool {
c.init()
return c.inner.Contains(key)
}
+
func (c *LRUCache[K, V]) Get(key K) (value V, ok bool) {
c.init()
_value, ok := c.inner.Get(key)
@@ -49,6 +51,7 @@ func (c *LRUCache[K, V]) Get(key K) (value V, ok bool) {
}
return value, ok
}
+
func (c *LRUCache[K, V]) Keys() []K {
c.init()
untyped := c.inner.Keys()
@@ -59,10 +62,12 @@ func (c *LRUCache[K, V]) Keys() []K {
}
return typed
}
+
func (c *LRUCache[K, V]) Len() int {
c.init()
return c.inner.Len()
}
+
func (c *LRUCache[K, V]) Peek(key K) (value V, ok bool) {
c.init()
_value, ok := c.inner.Peek(key)
@@ -72,10 +77,12 @@ func (c *LRUCache[K, V]) Peek(key K) (value V, ok bool) {
}
return value, ok
}
+
func (c *LRUCache[K, V]) Purge() {
c.init()
c.inner.Purge()
}
+
func (c *LRUCache[K, V]) Remove(key K) {
c.init()
c.inner.Remove(key)
diff --git a/lib/containers/syncmap.go b/lib/containers/syncmap.go
index 4af678f..74da4b3 100644
--- a/lib/containers/syncmap.go
+++ b/lib/containers/syncmap.go
@@ -15,6 +15,7 @@ type SyncMap[K comparable, V any] struct {
func (m *SyncMap[K, V]) Delete(key K) {
m.inner.Delete(key)
}
+
func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) {
_value, ok := m.inner.Load(key)
if ok {
@@ -23,6 +24,7 @@ func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) {
}
return value, ok
}
+
func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
_value, ok := m.inner.LoadAndDelete(key)
if ok {
@@ -31,18 +33,21 @@ func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
}
return value, ok
}
+
func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
_actual, loaded := m.inner.LoadOrStore(key, value)
//nolint:forcetypeassert // Typed wrapper around untyped lib.
actual = _actual.(V)
return actual, loaded
}
+
func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) {
m.inner.Range(func(key, value any) bool {
//nolint:forcetypeassert // Typed wrapper around untyped lib.
return f(key.(K), value.(V))
})
}
+
func (m *SyncMap[K, V]) Store(key K, value V) {
m.inner.Store(key, value)
}
diff --git a/lib/fmtutil/fmt.go b/lib/fmtutil/fmt.go
index 3898046..b310eb6 100644
--- a/lib/fmtutil/fmt.go
+++ b/lib/fmtutil/fmt.go
@@ -52,7 +52,8 @@ func FormatByteArrayStringer(
fmt.Formatter
},
objBytes []byte,
- f fmt.State, verb rune) {
+ f fmt.State, verb rune,
+) {
switch verb {
case 'v':
if !f.Flag('#') {
diff --git a/lib/textui/text.go b/lib/textui/text.go
index d6a80b3..615516d 100644
--- a/lib/textui/text.go
+++ b/lib/textui/text.go
@@ -72,9 +72,7 @@ type Portion[T constraints.Integer] struct {
N, D T
}
-var (
- _ fmt.Stringer = Portion[int]{}
-)
+var _ fmt.Stringer = Portion[int]{}
// String implements fmt.Stringer.
func (p Portion[T]) String() string {