Skip to content

Commit

Permalink
Merge pull request #1522 from rhatdan/VENDOR
Browse files Browse the repository at this point in the history
Move to golang 1.18 and later
  • Loading branch information
rhatdan authored Apr 4, 2023
2 parents b04c26b + a3204cf commit fab09d7
Show file tree
Hide file tree
Showing 373 changed files with 103,118 additions and 83,209 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ lint_task:
env:
CIRRUS_WORKING_DIR: "/go/src/github.com/containers/storage"
container:
image: golang:1.17
image: golang
modules_cache:
fingerprint_script: cat go.sum
folder: $GOPATH/pkg/mod
Expand Down Expand Up @@ -158,7 +158,7 @@ meta_task:

vendor_task:
container:
image: golang:1.17
image: golang
modules_cache:
fingerprint_script: cat go.sum
folder: $GOPATH/pkg/mod
Expand Down
36 changes: 35 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,70 @@
run:
concurrency: 6
deadline: 5m
skip-dirs-use-default: true
linters:
enable-all: true
disable:
- cyclop
- deadcode
- dogsled
- dupl
- errcheck
- errname
- errorlint
- exhaustive
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofumpt
- golint
- gomnd
- gosec
- gosimple
- govet
- ifshort
- ineffassign
- interfacer
- interfacebloat
- ireturn
- lll
- maintidx
- maligned
- misspell
- musttag
- nakedret
- nestif
- nlreturn
- nolintlint
- nonamedreturns
- nosnakecase
- paralleltest
- prealloc
- predeclared
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- testpackage
- thelper
- unconvert
- unparam
- unused
- varcheck
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-z A-Z_-]+:.*?## / {gsub(" ",",",$$1);gsub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-21s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

vendor-in-container:
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src golang:1.17 make vendor
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src golang make vendor

vendor:
$(GO) mod tidy -compat=1.17
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify
2 changes: 1 addition & 1 deletion drivers/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (a *Driver) Status() [][2]string {

// Metadata not implemented
func (a *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
return nil, nil //nolint: nilnil
}

// Exists returns true if the given id is registered with
Expand Down
2 changes: 1 addition & 1 deletion drivers/btrfs/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (d *Driver) Status() [][2]string {

// Metadata returns empty metadata for this driver.
func (d *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
return nil, nil //nolint: nilnil
}

// Cleanup unmounts the home directory.
Expand Down
4 changes: 2 additions & 2 deletions drivers/copy/copy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
)

// CopyRegularToFile copies the content of a file to another
func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { // nolint: golint
func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { // nolint: revive,golint
srcFile, err := os.Open(srcPath)
if err != nil {
return err
Expand Down Expand Up @@ -73,7 +73,7 @@ func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, c
}

// CopyRegular copies the content of a file to another
func CopyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { // nolint: golint
func CopyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { // nolint: revive,golint
// If the destination file already exists, we shouldn't blow it away
dstFile, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, fileinfo.Mode())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions drivers/copy/copy_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func DirCopy(srcDir, dstDir string, _ Mode, _ bool) error {
}

// CopyRegularToFile copies the content of a file to another
func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { //nolint: revive // "func name will be used as copy.CopyRegularToFile by other packages, and that stutters"
func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { //nolint: revive,golint // "func name will be used as copy.CopyRegularToFile by other packages, and that stutters"
f, err := os.Open(srcPath)
if err != nil {
return err
Expand All @@ -36,6 +36,6 @@ func CopyRegularToFile(srcPath string, dstFile *os.File, fileinfo os.FileInfo, c
}

// CopyRegular copies the content of a file to another
func CopyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { //nolint:revive // "func name will be used as copy.CopyRegular by other packages, and that stutters"
func CopyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRange, copyWithFileClone *bool) error { //nolint:revive,golint // "func name will be used as copy.CopyRegular by other packages, and that stutters"
return chrootarchive.NewArchiver(nil).CopyWithTar(srcPath, dstPath)
}
6 changes: 3 additions & 3 deletions drivers/devmapper/device_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func validateLVMConfig(cfg directLVMConfig) error {
func checkDevAvailable(dev string) error {
lvmScan, err := exec.LookPath("lvmdiskscan")
if err != nil {
logrus.Debug("could not find lvmdiskscan")
logrus.Debugf("could not find lvmdiskscan: %v", err)
return nil
}

Expand All @@ -67,7 +67,7 @@ func checkDevAvailable(dev string) error {
func checkDevInVG(dev string) error {
pvDisplay, err := exec.LookPath("pvdisplay")
if err != nil {
logrus.Debug("could not find pvdisplay")
logrus.Debugf("could not find pvdisplay: %v", err)
return nil
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func checkDevInVG(dev string) error {
func checkDevHasFS(dev string) error {
blkid, err := exec.LookPath("blkid")
if err != nil {
logrus.Debug("could not find blkid")
logrus.Debugf("could not find blkid %v", err)
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions drivers/devmapper/deviceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (devices *DeviceSet) loadDeviceFilesOnStart() error {

var scan = func(path string, d fs.DirEntry, err error) error {
if err != nil {
logrus.Debugf("devmapper: Can't walk the file %s", path)
logrus.Debugf("devmapper: Can't walk the file %s: %v", path, err)
return nil
}

Expand Down Expand Up @@ -2487,10 +2487,11 @@ func (devices *DeviceSet) deviceStatus(devName string) (sizeInSectors, mappedSec
var params string
_, sizeInSectors, _, params, err = devicemapper.GetStatus(devName)
if err != nil {
logrus.Debugf("could not find devicemapper status: %v", err)
return
}
if _, err = fmt.Sscanf(params, "%d %d", &mappedSectors, &highestMappedSector); err == nil {
return
if _, err = fmt.Sscanf(params, "%d %d", &mappedSectors, &highestMappedSector); err != nil {
logrus.Debugf("could not find scanf devicemapper status: %v", err)
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type MountOpts struct {
// Mount label is the MAC Labels to assign to mount point (SELINUX)
MountLabel string
// UidMaps & GidMaps are the User Namespace mappings to be assigned to content in the mount point
UidMaps []idtools.IDMap //nolint: golint,revive
GidMaps []idtools.IDMap //nolint: golint
UidMaps []idtools.IDMap //nolint: revive,golint
GidMaps []idtools.IDMap //nolint: revive,golint
Options []string

// Volatile specifies whether the container storage can be optimized
Expand Down
2 changes: 1 addition & 1 deletion drivers/driver_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *defaultChecker) IsMounted(path string) bool {
}

// Mounted checks if the given path is mounted as the fs type
//Solaris supports only ZFS for now
// Solaris supports only ZFS for now
func Mounted(fsType FsMagic, mountPath string) (bool, error) {

cs := C.CString(filepath.Dir(mountPath))
Expand Down
6 changes: 4 additions & 2 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ func parseOptions(options []string) (*overlayOptions, error) {
case "skip_mount_home":
logrus.Debugf("overlay: skip_mount_home=%s", val)
o.skipMountHome, err = strconv.ParseBool(val)
if err != nil {
return nil, err
}
case "ignore_chown_errors":
logrus.Debugf("overlay: ignore_chown_errors=%s", val)
o.ignoreChownErrors, err = strconv.ParseBool(val)
Expand Down Expand Up @@ -1438,7 +1441,6 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
perms = os.FileMode(st2.Mode())
permsKnown = true
}
l = lower
break
}
lower = ""
Expand Down Expand Up @@ -1826,7 +1828,7 @@ func (d *Driver) ApplyDiffWithDiffer(id, parent string, options *graphdriver.App
idMappings = &idtools.IDMappings{}
}

applyDir := ""
var applyDir string

if id == "" {
err := os.MkdirAll(d.getStagingDir(), 0700)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.17
go 1.18

module github.com/containers/storage

Expand Down
31 changes: 16 additions & 15 deletions internal/opts/opts_test.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
package opts
package opts_test

import (
"fmt"
"strings"
"testing"

"github.com/containers/storage/internal/opts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestValidateIPAddress(t *testing.T) {
if ret, err := ValidateIPAddress(`1.2.3.4`); err != nil || ret == "" {
if ret, err := opts.ValidateIPAddress(`1.2.3.4`); err != nil || ret == "" {
t.Fatalf("ValidateIPAddress(`1.2.3.4`) got %s %s", ret, err)
}

if ret, err := ValidateIPAddress(`127.0.0.1`); err != nil || ret == "" {
if ret, err := opts.ValidateIPAddress(`127.0.0.1`); err != nil || ret == "" {
t.Fatalf("ValidateIPAddress(`127.0.0.1`) got %s %s", ret, err)
}

if ret, err := ValidateIPAddress(`::1`); err != nil || ret == "" {
if ret, err := opts.ValidateIPAddress(`::1`); err != nil || ret == "" {
t.Fatalf("ValidateIPAddress(`::1`) got %s %s", ret, err)
}

if ret, err := ValidateIPAddress(`127`); err == nil || ret != "" {
if ret, err := opts.ValidateIPAddress(`127`); err == nil || ret != "" {
t.Fatalf("ValidateIPAddress(`127`) got %s %s", ret, err)
}

if ret, err := ValidateIPAddress(`random invalid string`); err == nil || ret != "" {
if ret, err := opts.ValidateIPAddress(`random invalid string`); err == nil || ret != "" {
t.Fatalf("ValidateIPAddress(`random invalid string`) got %s %s", ret, err)
}

}

func TestMapOpts(t *testing.T) {
tmpMap := make(map[string]string)
o := NewMapOpts(tmpMap, logOptsValidator)
o := opts.NewMapOpts(tmpMap, logOptsValidator)
err := o.Set("max-size=1")
require.NoError(t, err)
if o.String() != "map[max-size:1]" {
Expand All @@ -60,7 +61,7 @@ func TestMapOpts(t *testing.T) {
}

func TestListOptsWithoutValidator(t *testing.T) {
o := NewListOpts(nil)
o := opts.NewListOpts(nil)
err := o.Set("foo")
require.NoError(t, err)
if o.String() != "[foo]" {
Expand Down Expand Up @@ -99,7 +100,7 @@ func TestListOptsWithoutValidator(t *testing.T) {

func TestListOptsWithValidator(t *testing.T) {
// Re-using logOptsvalidator (used by MapOpts)
o := NewListOpts(logOptsValidator)
o := opts.NewListOpts(logOptsValidator)
err := o.Set("foo")
assert.EqualError(t, err, "invalid key foo")
if o.String() != "[]" {
Expand Down Expand Up @@ -128,18 +129,18 @@ func TestListOptsWithValidator(t *testing.T) {
}

func TestValidateLabel(t *testing.T) {
if _, err := ValidateLabel("label"); err == nil || err.Error() != "bad attribute format: label" {
if _, err := opts.ValidateLabel("label"); err == nil || err.Error() != "bad attribute format: label" {
t.Fatalf("Expected an error [bad attribute format: label], go %v", err)
}
if actual, err := ValidateLabel("key1=value1"); err != nil || actual != "key1=value1" {
if actual, err := opts.ValidateLabel("key1=value1"); err != nil || actual != "key1=value1" {
t.Fatalf("Expected [key1=value1], got [%v,%v]", actual, err)
}
// Validate it's working with more than one =
if actual, err := ValidateLabel("key1=value1=value2"); err != nil {
if actual, err := opts.ValidateLabel("key1=value1=value2"); err != nil {
t.Fatalf("Expected [key1=value1=value2], got [%v,%v]", actual, err)
}
// Validate it's working with one more
if actual, err := ValidateLabel("key1=value1=value2=value3"); err != nil {
if actual, err := opts.ValidateLabel("key1=value1=value2=value3"); err != nil {
t.Fatalf("Expected [key1=value1=value2=value2], got [%v,%v]", actual, err)
}
}
Expand All @@ -155,7 +156,7 @@ func logOptsValidator(val string) (string, error) {

func TestNamedListOpts(t *testing.T) {
var v []string
o := NewNamedListOptsRef("foo-name", &v, nil)
o := opts.NewNamedListOptsRef("foo-name", &v, nil)

err := o.Set("foo")
require.NoError(t, err)
Expand All @@ -172,7 +173,7 @@ func TestNamedListOpts(t *testing.T) {

func TestNamedMapOpts(t *testing.T) {
tmpMap := make(map[string]string)
o := NewNamedMapOpts("max-name", tmpMap, nil)
o := opts.NewNamedMapOpts("max-name", tmpMap, nil)

err := o.Set("max-size=1")
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/archive/archive_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (o overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi
}
// If there are no lower layers, then it can't have been deleted in this layer.
if len(o.rolayers) == 0 {
return nil, nil
return nil, nil //nolint: nilnil
}
// At this point, we have a directory that's opaque. If it appears in one of the lower
// layers, then it was newly-created here, so it wasn't also deleted here.
Expand All @@ -66,7 +66,7 @@ func (o overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi
if statErr == nil {
if stat.Mode()&os.ModeCharDevice != 0 {
if isWhiteOut(stat) {
return nil, nil
return nil, nil //nolint: nilnil
}
}
// It's not whiteout, so it was there in the older layer, so we need to
Expand Down Expand Up @@ -100,7 +100,7 @@ func (o overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi
// original directory wasn't inherited into this layer,
// so we don't need to emit whiteout for it.
if isWhiteOut(stat) {
return nil, nil
return nil, nil //nolint: nilnil
}
}
}
Expand Down
Loading

0 comments on commit fab09d7

Please sign in to comment.