Skip to content

Commit

Permalink
ci: enable staticcheck linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hughes committed Aug 27, 2021
1 parent 138a19c commit e0348f1
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ linters:
- misspell
- nakedret
- revive
- staticcheck
# we would like to add these
# - dupl
# - staticcheck

linters-settings:
misspell:
Expand Down
4 changes: 2 additions & 2 deletions cmd/internal/cli/singularity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -29,7 +29,7 @@ func TestCreateConfDir(t *testing.T) {
t.Errorf("failed to create directory %s", dir)
} else {
// stick something in the directory and make sure it isn't deleted
ioutil.WriteFile(dir+"/foo", []byte(""), 655)
ioutil.WriteFile(dir+"/foo", []byte(""), 0o655)
handleConfDir(dir)
if _, err := os.Stat(dir + "/foo"); os.IsNotExist(err) {
t.Errorf("inadvertently overwrote existing directory %s", dir)
Expand Down
4 changes: 2 additions & 2 deletions e2e/instance/instance_utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -126,7 +126,7 @@ func echo(t *testing.T, port int) {
return
}

fmt.Fprintf(sock, message)
fmt.Fprint(sock, message)

response, responseErr := bufio.NewReader(sock).ReadString('\n')
if responseErr != nil || response != message {
Expand Down
5 changes: 3 additions & 2 deletions internal/app/singularity/capability_manage_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand All @@ -7,6 +7,7 @@ package singularity

import (
"fmt"
"io"
"os"
"syscall"

Expand Down Expand Up @@ -107,7 +108,7 @@ func manageCaps(capFile string, c CapManageConfig, t manageType) error {
return fmt.Errorf("while truncating capability config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
7 changes: 3 additions & 4 deletions internal/app/singularity/remote_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package singularity

import (
"fmt"
"io"
"net/url"
"os"
"path"
Expand All @@ -26,8 +27,6 @@ func RemoteAdd(configFile, name, uri string, global, insecure bool) (err error)
return fmt.Errorf("invalid URI: cannot have empty URI")
}

c := &remote.Config{}

// system config should be world readable
perm := os.FileMode(0o600)
if global {
Expand All @@ -42,7 +41,7 @@ func RemoteAdd(configFile, name, uri string, global, insecure bool) (err error)
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand All @@ -62,7 +61,7 @@ func RemoteAdd(configFile, name, uri string, global, insecure bool) (err error)
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/app/singularity/remote_add_keyserver.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2021, Sylabs Inc. All rights reserved.
// Copyright (c) 2020, Control Command Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
Expand All @@ -7,6 +8,7 @@ package singularity

import (
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -56,7 +58,7 @@ func RemoteAddKeyserver(name, uri string, order uint32, insecure bool) error {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
9 changes: 4 additions & 5 deletions internal/app/singularity/remote_login.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2020, Control Command Inc. All rights reserved.
// Copyright (c) 2019-2020, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand All @@ -9,6 +9,7 @@ package singularity
import (
"errors"
"fmt"
"io"
"os"

"github.com/sylabs/singularity/internal/pkg/remote"
Expand All @@ -33,8 +34,6 @@ var ErrLoginAborted = errors.New("user aborted login")
// If the supplied remote name is an empty string, it will attempt
// to use the default remote.
func RemoteLogin(usrConfigFile string, args *LoginArgs) (err error) {
c := &remote.Config{}

// opening config file
file, err := os.OpenFile(usrConfigFile, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
Expand All @@ -43,7 +42,7 @@ func RemoteLogin(usrConfigFile string, args *LoginArgs) (err error) {
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand Down Expand Up @@ -83,7 +82,7 @@ func RemoteLogin(usrConfigFile string, args *LoginArgs) (err error) {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
9 changes: 4 additions & 5 deletions internal/app/singularity/remote_logout.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2020, Control Command Inc. All rights reserved.
// Copyright (c) 2019-2020, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand All @@ -8,6 +8,7 @@ package singularity

import (
"fmt"
"io"
"os"

"github.com/sylabs/singularity/internal/pkg/remote"
Expand All @@ -16,8 +17,6 @@ import (

// RemoteLogout logs out from an endpoint or service.
func RemoteLogout(usrConfigFile, name string) (err error) {
c := &remote.Config{}

// opening config file
file, err := os.OpenFile(usrConfigFile, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
Expand All @@ -26,7 +25,7 @@ func RemoteLogout(usrConfigFile, name string) (err error) {
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand Down Expand Up @@ -57,7 +56,7 @@ func RemoteLogout(usrConfigFile, name string) (err error) {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
7 changes: 3 additions & 4 deletions internal/app/singularity/remote_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ package singularity

import (
"fmt"
"io"
"os"

"github.com/sylabs/singularity/internal/pkg/remote"
)

// RemoteRemove deletes a remote endpoint from the configuration
func RemoteRemove(configFile, name string) (err error) {
c := &remote.Config{}

// opening config file
file, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
Expand All @@ -24,7 +23,7 @@ func RemoteRemove(configFile, name string) (err error) {
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand All @@ -38,7 +37,7 @@ func RemoteRemove(configFile, name string) (err error) {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/app/singularity/remote_remove_keyserver.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2021, Sylabs Inc. All rights reserved.
// Copyright (c) 2020, Control Command Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
Expand All @@ -7,6 +8,7 @@ package singularity

import (
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -56,7 +58,7 @@ func RemoteRemoveKeyserver(name, uri string) error {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
6 changes: 2 additions & 4 deletions internal/app/singularity/remote_status.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2020, Control Command Inc. All rights reserved.
// Copyright (c) 2019, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -31,8 +31,6 @@ type status struct {
// If the supplied remote name is an empty string, it will attempt
// to use the default remote.
func RemoteStatus(usrConfigFile, name string) (err error) {
c := &remote.Config{}

if name != "" {
sylog.Infof("Checking status of remote: %s", name)
} else {
Expand All @@ -50,7 +48,7 @@ func RemoteStatus(usrConfigFile, name string) (err error) {
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/app/singularity/remote_use.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package singularity

import (
"fmt"
"io"
"os"

"github.com/sylabs/singularity/internal/pkg/remote"
Expand Down Expand Up @@ -35,8 +36,6 @@ func syncSysConfig(cUsr *remote.Config) error {

// RemoteUse sets remote to use
func RemoteUse(usrConfigFile, name string, global, exclusive bool) (err error) {
c := &remote.Config{}

if exclusive {
if os.Getuid() != 0 {
return fmt.Errorf("unable to set endpoint as exclusive: not root user")
Expand All @@ -59,7 +58,7 @@ func RemoteUse(usrConfigFile, name string, global, exclusive bool) (err error) {
defer file.Close()

// read file contents to config struct
c, err = remote.ReadFrom(file)
c, err := remote.ReadFrom(file)
if err != nil {
return fmt.Errorf("while parsing remote config data: %s", err)
}
Expand All @@ -79,7 +78,7 @@ func RemoteUse(usrConfigFile, name string, global, exclusive bool) (err error) {
return fmt.Errorf("while truncating remote config file: %s", err)
}

if n, err := file.Seek(0, os.SEEK_SET); err != nil || n != 0 {
if n, err := file.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("failed to reset %s cursor: %s", file.Name(), err)
}

Expand Down
10 changes: 1 addition & 9 deletions internal/app/starter/master_linux_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -62,10 +62,6 @@ func TestCreateContainer(t *testing.T) {
t.Fatalf("test %s expected to succeed but failed: %s", tt.name, fatal)
} else if !tt.shallPass && fatal == nil {
t.Fatalf("test %s expected to fail but succeeded", tt.name)
} else if tt.shallPass && fatal == nil {
// test succeed
} else if !tt.shallPass && fatal != nil {
// test succeed
}
})
}
Expand Down Expand Up @@ -109,10 +105,6 @@ func TestStartContainer(t *testing.T) {
t.Fatalf("test %s expected to succeed but failed: %s", tt.name, fatal)
} else if !tt.shallPass && fatal == nil {
t.Fatalf("test %s expected to fail but succeeded", tt.name)
} else if tt.shallPass && fatal == nil {
// test succeed
} else if !tt.shallPass && fatal != nil {
// test succeed
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/fakeroot/fakeroot.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand All @@ -9,6 +9,7 @@ import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -183,7 +184,7 @@ func (c *Config) Close() error {
if err := c.file.Truncate(0); err != nil {
return fmt.Errorf("error while truncating %s to 0: %s", filename, err)
}
if _, err := c.file.Seek(0, os.SEEK_SET); err != nil {
if _, err := c.file.Seek(0, io.SeekStart); err != nil {
return fmt.Errorf("error while resetting file offset: %s", err)
}
if _, err := c.file.Write(buf.Bytes()); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/runtime/engine/singularity/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2428,13 +2428,12 @@ func (c *container) openFuseFdFromRPC() (int, int, error) {

fuseFd := -1

for _, msg := range msgs {
fds, err := unix.ParseUnixRights(&msg)
if len(msgs) > 0 {
fds, err := unix.ParseUnixRights(&msgs[0])
if err != nil {
return -1, -1, fmt.Errorf("while getting file descriptor: %s", err)
}
fuseFd = fds[0]
break
}

return fuseFd, fuseRPCFd, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/util/fs/layout/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
dirMode os.FileMode = 0o755
fileMode = 0o644
fileMode os.FileMode = 0o644
)

type file struct {
Expand Down
Loading

0 comments on commit e0348f1

Please sign in to comment.