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
- gofmt
- goimports
- golint
- goprintffuncname
- interfacer
- rowserrcheck
@ -25,7 +26,6 @@ linters:
- gocritic
- gocyclo
- godox
- golint
- gomnd
- gosec
- gosimple

View File

@ -25,14 +25,14 @@ func platformLChown(path string, info os.FileInfo, toHost, toContainer *idtools.
UID: uid,
GID: gid,
}
mappedUid, mappedGid, err := toContainer.ToContainer(pair)
mappedUID, mappedGID, err := toContainer.ToContainer(pair)
if err != nil {
if (uid != 0) || (gid != 0) {
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 {
pair := idtools.IDPair{

View File

@ -48,9 +48,9 @@ type CreateOpts struct {
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
GidMaps []idtools.IDMap
// UIDMaps & GIDMaps are the User Namespace mappings to be assigned to content in the mount point
UIDMaps []idtools.IDMap
GIDMaps []idtools.IDMap
Options []string
}

View File

@ -401,9 +401,8 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
if err == nil {
logrus.Debugf("overlay test mount with multiple lowers succeeded")
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)
if len(flags) < unix.Getpagesize() {
@ -411,9 +410,8 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
if err == nil {
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")
} 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)
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 != "" {
mountFunc = func(source string, target string, mType string, flags uintptr, label string) error {
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)

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

View File

@ -793,8 +793,8 @@ func (r *layerStore) Mount(id string, options drivers.MountOpts) (string, error)
options.MountLabel = layer.MountLabel
}
if (options.UidMaps != nil || options.GidMaps != nil) && !r.driver.SupportsShifting() {
if !reflect.DeepEqual(options.UidMaps, layer.UIDMap) || !reflect.DeepEqual(options.GidMaps, layer.GIDMap) {
if (options.UIDMaps != nil || options.GIDMaps != nil) && !r.driver.SupportsShifting() {
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)
}
}

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 {
// 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()
if cuid, cgid, err := newInfo.idMappings.ToContainer(idtools.IDPair{UID: int(uid), GID: int(gid)}); err == nil {
uid = uint32(cuid)
gid = uint32(cgid)
if oldcuid, oldcgid, err := oldInfo.idMappings.ToContainer(idtools.IDPair{UID: int(oldUid), GID: int(oldGid)}); err == nil {
oldUid = uint32(oldcuid)
oldGid = uint32(oldcgid)
if oldcuid, oldcgid, err := oldInfo.idMappings.ToContainer(idtools.IDPair{UID: int(oldUID), GID: int(oldGID)}); err == nil {
oldUID = uint32(oldcuid)
oldGID = uint32(oldcgid)
}
}
ownerChanged := uid != oldUid || gid != oldGid
ownerChanged := uid != oldUID || gid != oldGID
if oldStat.Mode() != newStat.Mode() ||
ownerChanged ||
oldStat.Rdev() != newStat.Rdev() ||

View File

@ -690,14 +690,18 @@ func TestLockfileMultiprocessMixed(t *testing.T) {
var wg sync.WaitGroup
var rcounter, wcounter, rhighest, whighest int64
var rhighestMutex, whighestMutex sync.Mutex
bias_p := 1
bias_q := 10
groups := 15
writer := func(i int) bool { return (i % bias_q) < bias_p }
const (
biasP = 1
biasQ = 10
groups = 15
)
writer := func(i int) bool { return (i % biasQ) < biasP }
subs := make([]struct {
stdin io.WriteCloser
stdout io.ReadCloser
}, bias_q*groups)
}, biasQ*groups)
for i := range subs {
var stdin io.WriteCloser
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
// command.
func (l *lockfile) lock(l_type int16, recursive bool) {
func (l *lockfile) lock(lType int16, recursive bool) {
lk := unix.Flock_t{
Type: l_type,
Type: lType,
Whence: int16(os.SEEK_SET),
Start: 0,
Len: 0,
}
switch l_type {
switch lType {
case unix.F_RDLCK:
l.rwMutex.RLock()
case unix.F_WRLCK:
@ -96,7 +96,7 @@ func (l *lockfile) lock(l_type int16, recursive bool) {
l.rwMutex.Lock()
}
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()
defer l.stateMutex.Unlock()
@ -116,7 +116,7 @@ func (l *lockfile) lock(l_type int16, recursive bool) {
time.Sleep(10 * time.Millisecond)
}
}
l.locktype = l_type
l.locktype = lType
l.locked = true
l.recursive = recursive
l.counter++

View File

@ -2505,8 +2505,8 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
if rlstore.Exists(id) {
options := drivers.MountOpts{
MountLabel: mountLabel,
UidMaps: uidMap,
GidMaps: gidMap,
UIDMaps: uidMap,
GIDMaps: gidMap,
Options: mountOpts,
}
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
func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
path, err := getRootlessRuntimeDir(rootlessUid)
func GetRootlessRuntimeDir(rootlessUID int) (string, error) {
path, err := getRootlessRuntimeDir(rootlessUID)
if err != nil {
return "", err
}
@ -81,18 +81,18 @@ func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
return path, nil
}
func getRootlessRuntimeDir(rootlessUid int) (string, error) {
func getRootlessRuntimeDir(rootlessUID int) (string, error) {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir != "" {
return runtimeDir, nil
}
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid)
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUID)
st, err := system.Stat(tmpDir)
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
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 {
logrus.Errorf("failed to create %s: %v", tmpDir, err)
} else {
@ -111,8 +111,8 @@ func getRootlessRuntimeDir(rootlessUid int) (string, error) {
// getRootlessDirInfo returns the parent path of where the storage for containers and
// volumes will be in rootless mode
func getRootlessDirInfo(rootlessUid int) (string, string, error) {
rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUid)
func getRootlessDirInfo(rootlessUID int) (string, string, error) {
rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUID)
if err != nil {
return "", "", err
}
@ -135,10 +135,10 @@ func getRootlessDirInfo(rootlessUid int) (string, string, error) {
}
// 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
dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUid)
dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUID)
if err != nil {
return opts, err
}
@ -185,21 +185,21 @@ func DefaultStoreOptionsAutoDetectUID() (StoreOptions, error) {
}
// 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 (
defaultRootlessRunRoot string
defaultRootlessGraphRoot string
err error
)
storageOpts := defaultStoreOptions
if rootless && rootlessUid != 0 {
storageOpts, err = getRootlessStorageOpts(rootlessUid)
if rootless && rootlessUID != 0 {
storageOpts, err = getRootlessStorageOpts(rootlessUID)
if err != nil {
return storageOpts, err
}
}
storageConf, err := DefaultConfigFile(rootless && rootlessUid != 0)
storageConf, err := DefaultConfigFile(rootless && rootlessUID != 0)
if err != nil {
return storageOpts, err
}
@ -214,7 +214,7 @@ func DefaultStoreOptions(rootless bool, rootlessUid int) (StoreOptions, error) {
ReloadConfigurationFile(storageConf, &storageOpts)
}
if rootless && rootlessUid != 0 {
if rootless && rootlessUID != 0 {
if err == nil {
// If the file did not specify a graphroot or runroot,
// set sane defaults so we don't try and use root-owned