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>
This commit is contained in:
parent
bb59d4611e
commit
04b578ae9a
|
|
@ -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?")
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue