Enable golint linter and fix lints

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
Sascha Grunert 2020-01-28 15:08:39 +01:00
parent d88ef6dc08
commit fd72b45a3f
No known key found for this signature in database
GPG Key ID: 8CE029DD1A866E52
12 changed files with 58 additions and 2212 deletions

View File

@ -10,6 +10,7 @@ linters:
- goconst - goconst
- gofmt - gofmt
- goimports - goimports
- golint
- goprintffuncname - goprintffuncname
- interfacer - interfacer
- rowserrcheck - rowserrcheck
@ -25,7 +26,6 @@ linters:
- gocritic - gocritic
- gocyclo - gocyclo
- godox - godox
- golint
- gomnd - gomnd
- gosec - gosec
- gosimple - gosimple

View File

@ -25,14 +25,14 @@ func platformLChown(path string, info os.FileInfo, toHost, toContainer *idtools.
UID: uid, UID: uid,
GID: gid, GID: gid,
} }
mappedUid, mappedGid, err := toContainer.ToContainer(pair) mappedUID, mappedGID, err := toContainer.ToContainer(pair)
if err != nil { if err != nil {
if (uid != 0) || (gid != 0) { if (uid != 0) || (gid != 0) {
return fmt.Errorf("error mapping host ID pair %#v for %q to container: %v", pair, path, err) return fmt.Errorf("error mapping host ID pair %#v for %q to container: %v", pair, path, err)
} }
mappedUid, mappedGid = uid, gid mappedUID, mappedGID = uid, gid
} }
uid, gid = mappedUid, mappedGid uid, gid = mappedUID, mappedGID
} }
if toHost != nil { if toHost != nil {
pair := idtools.IDPair{ pair := idtools.IDPair{

View File

@ -48,9 +48,9 @@ type CreateOpts struct {
type MountOpts struct { type MountOpts struct {
// Mount label is the MAC Labels to assign to mount point (SELINUX) // Mount label is the MAC Labels to assign to mount point (SELINUX)
MountLabel string MountLabel string
// UidMaps & GidMaps are the User Namespace mappings to be assigned to content in the mount point // UIDMaps & GIDMaps are the User Namespace mappings to be assigned to content in the mount point
UidMaps []idtools.IDMap UIDMaps []idtools.IDMap
GidMaps []idtools.IDMap GIDMaps []idtools.IDMap
Options []string Options []string
} }

View File

@ -401,9 +401,8 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
if err == nil { if err == nil {
logrus.Debugf("overlay test mount with multiple lowers succeeded") logrus.Debugf("overlay test mount with multiple lowers succeeded")
return supportsDType, nil return supportsDType, nil
} else {
logrus.Debugf("overlay test mount with multiple lowers failed %v", err)
} }
logrus.Debugf("overlay test mount with multiple lowers failed %v", err)
} }
flags = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lower1Dir, upperDir, workDir) flags = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lower1Dir, upperDir, workDir)
if len(flags) < unix.Getpagesize() { if len(flags) < unix.Getpagesize() {
@ -411,9 +410,8 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
if err == nil { if err == nil {
logrus.Errorf("overlay test mount with multiple lowers failed, but succeeded with a single lower") logrus.Errorf("overlay test mount with multiple lowers failed, but succeeded with a single lower")
return supportsDType, errors.Wrap(graphdriver.ErrNotSupported, "kernel too old to provide multiple lowers feature for overlay") return supportsDType, errors.Wrap(graphdriver.ErrNotSupported, "kernel too old to provide multiple lowers feature for overlay")
} else {
logrus.Debugf("overlay test mount with a single lower failed %v", err)
} }
logrus.Debugf("overlay test mount with a single lower failed %v", err)
} }
logrus.Errorf("'overlay' is not supported over %s at %q", backingFs, home) logrus.Errorf("'overlay' is not supported over %s at %q", backingFs, home)
return supportsDType, errors.Wrapf(graphdriver.ErrIncompatibleFS, "'overlay' is not supported over %s at %q", backingFs, home) return supportsDType, errors.Wrapf(graphdriver.ErrIncompatibleFS, "'overlay' is not supported over %s at %q", backingFs, home)
@ -954,7 +952,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
if d.options.mountProgram != "" { if d.options.mountProgram != "" {
mountFunc = func(source string, target string, mType string, flags uintptr, label string) error { mountFunc = func(source string, target string, mType string, flags uintptr, label string) error {
if !disableShifting { if !disableShifting {
label = d.optsAppendMappings(label, options.UidMaps, options.GidMaps) label = d.optsAppendMappings(label, options.UIDMaps, options.GIDMaps)
} }
mountProgram := exec.Command(d.options.mountProgram, "-o", label, target) mountProgram := exec.Command(d.options.mountProgram, "-o", label, target)

View File

@ -214,17 +214,17 @@ func bigDataNameIsManifest(name string) bool {
// recomputeDigests takes a fixed digest and a name-to-digest map and builds a // recomputeDigests takes a fixed digest and a name-to-digest map and builds a
// list of the unique values that would identify the image. // list of the unique values that would identify the image.
func (image *Image) recomputeDigests() error { func (i *Image) recomputeDigests() error {
validDigests := make([]digest.Digest, 0, len(image.BigDataDigests)+1) validDigests := make([]digest.Digest, 0, len(i.BigDataDigests)+1)
digests := make(map[digest.Digest]struct{}) digests := make(map[digest.Digest]struct{})
if image.Digest != "" { if i.Digest != "" {
if err := image.Digest.Validate(); err != nil { if err := i.Digest.Validate(); err != nil {
return errors.Wrapf(err, "error validating image digest %q", string(image.Digest)) return errors.Wrapf(err, "error validating image digest %q", string(i.Digest))
} }
digests[image.Digest] = struct{}{} digests[i.Digest] = struct{}{}
validDigests = append(validDigests, image.Digest) validDigests = append(validDigests, i.Digest)
} }
for name, digest := range image.BigDataDigests { for name, digest := range i.BigDataDigests {
if !bigDataNameIsManifest(name) { if !bigDataNameIsManifest(name) {
continue continue
} }
@ -237,10 +237,10 @@ func (image *Image) recomputeDigests() error {
validDigests = append(validDigests, digest) validDigests = append(validDigests, digest)
} }
} }
if image.Digest == "" && len(validDigests) > 0 { if i.Digest == "" && len(validDigests) > 0 {
image.Digest = validDigests[0] i.Digest = validDigests[0]
} }
image.Digests = validDigests i.Digests = validDigests
return nil return nil
} }

View File

@ -793,8 +793,8 @@ func (r *layerStore) Mount(id string, options drivers.MountOpts) (string, error)
options.MountLabel = layer.MountLabel options.MountLabel = layer.MountLabel
} }
if (options.UidMaps != nil || options.GidMaps != nil) && !r.driver.SupportsShifting() { if (options.UIDMaps != nil || options.GIDMaps != nil) && !r.driver.SupportsShifting() {
if !reflect.DeepEqual(options.UidMaps, layer.UIDMap) || !reflect.DeepEqual(options.GidMaps, layer.GIDMap) { if !reflect.DeepEqual(options.UIDMaps, layer.UIDMap) || !reflect.DeepEqual(options.GIDMaps, layer.GIDMap) {
return "", fmt.Errorf("cannot mount layer %v: shifting not enabled", layer.ID) return "", fmt.Errorf("cannot mount layer %v: shifting not enabled", layer.ID)
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -13,17 +13,17 @@ import (
func statDifferent(oldStat *system.StatT, oldInfo *FileInfo, newStat *system.StatT, newInfo *FileInfo) bool { func statDifferent(oldStat *system.StatT, oldInfo *FileInfo, newStat *system.StatT, newInfo *FileInfo) bool {
// Don't look at size for dirs, its not a good measure of change // Don't look at size for dirs, its not a good measure of change
oldUid, oldGid := oldStat.UID(), oldStat.GID() oldUID, oldGID := oldStat.UID(), oldStat.GID()
uid, gid := newStat.UID(), newStat.GID() uid, gid := newStat.UID(), newStat.GID()
if cuid, cgid, err := newInfo.idMappings.ToContainer(idtools.IDPair{UID: int(uid), GID: int(gid)}); err == nil { if cuid, cgid, err := newInfo.idMappings.ToContainer(idtools.IDPair{UID: int(uid), GID: int(gid)}); err == nil {
uid = uint32(cuid) uid = uint32(cuid)
gid = uint32(cgid) gid = uint32(cgid)
if oldcuid, oldcgid, err := oldInfo.idMappings.ToContainer(idtools.IDPair{UID: int(oldUid), GID: int(oldGid)}); err == nil { if oldcuid, oldcgid, err := oldInfo.idMappings.ToContainer(idtools.IDPair{UID: int(oldUID), GID: int(oldGID)}); err == nil {
oldUid = uint32(oldcuid) oldUID = uint32(oldcuid)
oldGid = uint32(oldcgid) oldGID = uint32(oldcgid)
} }
} }
ownerChanged := uid != oldUid || gid != oldGid ownerChanged := uid != oldUID || gid != oldGID
if oldStat.Mode() != newStat.Mode() || if oldStat.Mode() != newStat.Mode() ||
ownerChanged || ownerChanged ||
oldStat.Rdev() != newStat.Rdev() || oldStat.Rdev() != newStat.Rdev() ||

View File

@ -690,14 +690,18 @@ func TestLockfileMultiprocessMixed(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
var rcounter, wcounter, rhighest, whighest int64 var rcounter, wcounter, rhighest, whighest int64
var rhighestMutex, whighestMutex sync.Mutex var rhighestMutex, whighestMutex sync.Mutex
bias_p := 1
bias_q := 10 const (
groups := 15 biasP = 1
writer := func(i int) bool { return (i % bias_q) < bias_p } biasQ = 10
groups = 15
)
writer := func(i int) bool { return (i % biasQ) < biasP }
subs := make([]struct { subs := make([]struct {
stdin io.WriteCloser stdin io.WriteCloser
stdout io.ReadCloser stdout io.ReadCloser
}, bias_q*groups) }, biasQ*groups)
for i := range subs { for i := range subs {
var stdin io.WriteCloser var stdin io.WriteCloser
var stdout io.ReadCloser var stdout io.ReadCloser

View File

@ -77,14 +77,14 @@ func createLockerForPath(path string, ro bool) (Locker, error) {
// lock locks the lockfile via FCTNL(2) based on the specified type and // lock locks the lockfile via FCTNL(2) based on the specified type and
// command. // command.
func (l *lockfile) lock(l_type int16, recursive bool) { func (l *lockfile) lock(lType int16, recursive bool) {
lk := unix.Flock_t{ lk := unix.Flock_t{
Type: l_type, Type: lType,
Whence: int16(os.SEEK_SET), Whence: int16(os.SEEK_SET),
Start: 0, Start: 0,
Len: 0, Len: 0,
} }
switch l_type { switch lType {
case unix.F_RDLCK: case unix.F_RDLCK:
l.rwMutex.RLock() l.rwMutex.RLock()
case unix.F_WRLCK: case unix.F_WRLCK:
@ -96,7 +96,7 @@ func (l *lockfile) lock(l_type int16, recursive bool) {
l.rwMutex.Lock() l.rwMutex.Lock()
} }
default: default:
panic(fmt.Sprintf("attempted to acquire a file lock of unrecognized type %d", l_type)) panic(fmt.Sprintf("attempted to acquire a file lock of unrecognized type %d", lType))
} }
l.stateMutex.Lock() l.stateMutex.Lock()
defer l.stateMutex.Unlock() defer l.stateMutex.Unlock()
@ -116,7 +116,7 @@ func (l *lockfile) lock(l_type int16, recursive bool) {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
} }
} }
l.locktype = l_type l.locktype = lType
l.locked = true l.locked = true
l.recursive = recursive l.recursive = recursive
l.counter++ l.counter++

View File

@ -2505,8 +2505,8 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
if rlstore.Exists(id) { if rlstore.Exists(id) {
options := drivers.MountOpts{ options := drivers.MountOpts{
MountLabel: mountLabel, MountLabel: mountLabel,
UidMaps: uidMap, UIDMaps: uidMap,
GidMaps: gidMap, GIDMaps: gidMap,
Options: mountOpts, Options: mountOpts,
} }
return rlstore.Mount(id, options) return rlstore.Mount(id, options)

View File

@ -69,8 +69,8 @@ func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap stri
} }
// GetRootlessRuntimeDir returns the runtime directory when running as non root // GetRootlessRuntimeDir returns the runtime directory when running as non root
func GetRootlessRuntimeDir(rootlessUid int) (string, error) { func GetRootlessRuntimeDir(rootlessUID int) (string, error) {
path, err := getRootlessRuntimeDir(rootlessUid) path, err := getRootlessRuntimeDir(rootlessUID)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -81,18 +81,18 @@ func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
return path, nil return path, nil
} }
func getRootlessRuntimeDir(rootlessUid int) (string, error) { func getRootlessRuntimeDir(rootlessUID int) (string, error) {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR") runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir != "" { if runtimeDir != "" {
return runtimeDir, nil return runtimeDir, nil
} }
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid) tmpDir := fmt.Sprintf("/run/user/%d", rootlessUID)
st, err := system.Stat(tmpDir) st, err := system.Stat(tmpDir)
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 { if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
return tmpDir, nil return tmpDir, nil
} }
tmpDir = fmt.Sprintf("%s/%d", os.TempDir(), rootlessUid) tmpDir = fmt.Sprintf("%s/%d", os.TempDir(), rootlessUID)
if err := os.MkdirAll(tmpDir, 0700); err != nil { if err := os.MkdirAll(tmpDir, 0700); err != nil {
logrus.Errorf("failed to create %s: %v", tmpDir, err) logrus.Errorf("failed to create %s: %v", tmpDir, err)
} else { } else {
@ -111,8 +111,8 @@ func getRootlessRuntimeDir(rootlessUid int) (string, error) {
// getRootlessDirInfo returns the parent path of where the storage for containers and // getRootlessDirInfo returns the parent path of where the storage for containers and
// volumes will be in rootless mode // volumes will be in rootless mode
func getRootlessDirInfo(rootlessUid int) (string, string, error) { func getRootlessDirInfo(rootlessUID int) (string, string, error) {
rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUid) rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUID)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
@ -135,10 +135,10 @@ func getRootlessDirInfo(rootlessUid int) (string, string, error) {
} }
// getRootlessStorageOpts returns the storage opts for containers running as non root // getRootlessStorageOpts returns the storage opts for containers running as non root
func getRootlessStorageOpts(rootlessUid int) (StoreOptions, error) { func getRootlessStorageOpts(rootlessUID int) (StoreOptions, error) {
var opts StoreOptions var opts StoreOptions
dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUid) dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUID)
if err != nil { if err != nil {
return opts, err return opts, err
} }
@ -185,21 +185,21 @@ func DefaultStoreOptionsAutoDetectUID() (StoreOptions, error) {
} }
// DefaultStoreOptions returns the default storage ops for containers // DefaultStoreOptions returns the default storage ops for containers
func DefaultStoreOptions(rootless bool, rootlessUid int) (StoreOptions, error) { func DefaultStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
var ( var (
defaultRootlessRunRoot string defaultRootlessRunRoot string
defaultRootlessGraphRoot string defaultRootlessGraphRoot string
err error err error
) )
storageOpts := defaultStoreOptions storageOpts := defaultStoreOptions
if rootless && rootlessUid != 0 { if rootless && rootlessUID != 0 {
storageOpts, err = getRootlessStorageOpts(rootlessUid) storageOpts, err = getRootlessStorageOpts(rootlessUID)
if err != nil { if err != nil {
return storageOpts, err return storageOpts, err
} }
} }
storageConf, err := DefaultConfigFile(rootless && rootlessUid != 0) storageConf, err := DefaultConfigFile(rootless && rootlessUID != 0)
if err != nil { if err != nil {
return storageOpts, err return storageOpts, err
} }
@ -214,7 +214,7 @@ func DefaultStoreOptions(rootless bool, rootlessUid int) (StoreOptions, error) {
ReloadConfigurationFile(storageConf, &storageOpts) ReloadConfigurationFile(storageConf, &storageOpts)
} }
if rootless && rootlessUid != 0 { if rootless && rootlessUID != 0 {
if err == nil { if err == nil {
// If the file did not specify a graphroot or runroot, // If the file did not specify a graphroot or runroot,
// set sane defaults so we don't try and use root-owned // set sane defaults so we don't try and use root-owned