Skip to content

Commit

Permalink
pidfile: golangci-lint fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub authored and askervin committed Dec 11, 2024
1 parent c52c7d4 commit 7dbcb38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/pidfile/pidfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strconv"
"strings"
"syscall"

logger "github.com/containers/nri-plugins/pkg/log"
)

var (
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/pidfile/pidfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package pidfile

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -46,7 +45,7 @@ func TestDefaults(t *testing.T) {
err error
)

Remove()
require.NoError(t, Remove())

err = Write()
require.Nil(t, err)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 7dbcb38

Please sign in to comment.