From 7dbcb38b16cf6b88b089e351fa3135f8cbf08b8b Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Mon, 9 Dec 2024 19:06:16 +0200 Subject: [PATCH] pidfile: golangci-lint fixes. Signed-off-by: Krisztian Litkey --- pkg/pidfile/pidfile.go | 6 +++++- pkg/pidfile/pidfile_test.go | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/pidfile/pidfile.go b/pkg/pidfile/pidfile.go index b5b3cb38b..59f5a0cd3 100644 --- a/pkg/pidfile/pidfile.go +++ b/pkg/pidfile/pidfile.go @@ -21,6 +21,8 @@ import ( "strconv" "strings" "syscall" + + logger "github.com/containers/nri-plugins/pkg/log" ) var ( @@ -93,7 +95,9 @@ func Read() (int, error) { // close closes the PID file and truncates it to zero length. func close() { if pidFile != nil { - pidFile.Truncate(0) + if err := pidFile.Truncate(0); err != nil { + logger.Default().Warnf("failed to truncate PID file: %v\n", err) + } pidFile.Close() pidFile = nil } diff --git a/pkg/pidfile/pidfile_test.go b/pkg/pidfile/pidfile_test.go index d969ed992..2ddbd3f94 100644 --- a/pkg/pidfile/pidfile_test.go +++ b/pkg/pidfile/pidfile_test.go @@ -16,7 +16,6 @@ package pidfile import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -46,7 +45,7 @@ func TestDefaults(t *testing.T) { err error ) - Remove() + require.NoError(t, Remove()) err = Write() require.Nil(t, err) @@ -66,7 +65,7 @@ func TestDefaults(t *testing.T) { err = Write() require.NotNil(t, err) - Remove() + require.NoError(t, Remove()) err = Write() require.Nil(t, err) @@ -242,7 +241,7 @@ func TestOwnerPid(t *testing.T) { } func mkTestDir(t *testing.T) (string, error) { - tmp, err := ioutil.TempDir("", ".pidfile-test*") + tmp, err := os.MkdirTemp("", ".pidfile-test*") if err != nil { return "", fmt.Errorf("failed to create test directory: %w", err) }