Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix issues reported by errcheck
Mainly type casting issues. I ignored some of them where I don't think
it can fail or when it is in tests where we would notice anyway.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Feb 14, 2025
commit eed7689f146f10007683f214d3a5d7a633d37561
2 changes: 2 additions & 0 deletions libimage/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestSaveLoad(t *testing.T) {
}()

list := Create()
//nolint:errcheck
list.(listPtr).artifacts.Detached[otherListDigest] = "relative-path-names-are-messy" // set to check that this data is recorded
assert.NotNil(t, list, "Create() returned nil?")

Expand All @@ -104,6 +105,7 @@ func TestSaveLoad(t *testing.T) {
assert.NoError(t, err, "LoadFromImage(3)")
assert.NotNilf(t, list, "LoadFromImage(3)")

//nolint:errcheck
assert.Equal(t, list.(listPtr).artifacts.Detached[otherListDigest], "relative-path-names-are-messy") // check that this data is loaded
}

Expand Down
4 changes: 4 additions & 0 deletions libnetwork/slirp4netns/slirp4netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ func openSlirp4netnsPort(apiSocket, proto, hostip string, hostport, guestport ui
if _, err := conn.Write([]byte(fmt.Sprintf("%s\n", data))); err != nil {
return fmt.Errorf("cannot write to control socket %s: %w", apiSocket, err)
}
//nolint:errcheck // This cast should never fail, if it does we get a interface
// conversion panic and a stack trace on how we ended up here which is more
// valuable than returning a human friendly error test as we don't know how it
// happened.
if err := conn.(*net.UnixConn).CloseWrite(); err != nil {
return fmt.Errorf("cannot shutdown the socket %s: %w", apiSocket, err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/cgroups/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,16 @@ func UserOwnsCurrentSystemdCgroup() (bool, error) {
if err != nil {
return false, err
}

s := st.Sys()
if s == nil {
return false, fmt.Errorf("stat cgroup path %s", cgroupPath)
return false, fmt.Errorf("stat cgroup path is nil %s", cgroupPath)
}

//nolint:errcheck // This cast should never fail, if it does we get a interface
// conversion panic and a stack trace on how we ended up here which is more
// valuable than returning a human friendly error test as we don't know how it
// happened.
if int(s.(*syscall.Stat_t).Uid) != uid {
return false, nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/chown/chown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ func TestChangeHostPathOwnership(t *testing.T) {
t.Fatal(err)
}

sys, ok := f.Sys().(*syscall.Stat_t)
if !ok {
t.Fatal("failed to cast stat to *syscall.Stat_t")
}
// Get current ownership
currentUID := int(f.Sys().(*syscall.Stat_t).Uid)
currentGID := int(f.Sys().(*syscall.Stat_t).Gid)
currentUID := int(sys.Uid)
currentGID := int(sys.Gid)

tests := []struct {
Path string
Expand Down
12 changes: 8 additions & 4 deletions pkg/chown/chown_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func ChangeHostPathOwnership(path string, recursive bool, uid, gid int) error {
return err
}

//nolint:errcheck
stat := f.Sys().(*syscall.Stat_t)
// Get current ownership
currentUID := int(f.Sys().(*syscall.Stat_t).Uid)
currentGID := int(f.Sys().(*syscall.Stat_t).Gid)
currentUID := int(stat.Uid)
currentGID := int(stat.Gid)

if uid != currentUID || gid != currentGID {
return os.Lchown(filePath, uid, gid)
Expand All @@ -49,9 +51,11 @@ func ChangeHostPathOwnership(path string, recursive bool, uid, gid int) error {
return fmt.Errorf("failed to get host path information: %w", err)
}

//nolint:errcheck
stat := f.Sys().(*syscall.Stat_t)
// Get current ownership
currentUID := int(f.Sys().(*syscall.Stat_t).Uid)
currentGID := int(f.Sys().(*syscall.Stat_t).Gid)
currentUID := int(stat.Uid)
currentGID := int(stat.Gid)

if uid != currentUID || gid != currentGID {
if err := os.Lchown(path, uid, gid); err != nil {
Expand Down