Merge pull request #36011 from thaJeztah/golint-fixes
Golint and Ineffassign fixes Upstream-commit: a44274f1c033004f0aaaa225aa98c58c018623f6 Component: engine
This commit is contained in:
@@ -11,8 +11,10 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
// APIVersionKey is the client's requested API version.
|
||||
const APIVersionKey = "api-version"
|
||||
const APIVersionKey contextKey = "api-version"
|
||||
|
||||
// APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
|
||||
// Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion).
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@@ -57,8 +58,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
|
||||
if versions.GreaterThan(apiVersion, v.defaultVersion) {
|
||||
return versionUnsupportedError{version: apiVersion, maxVersion: v.defaultVersion}
|
||||
}
|
||||
// nolint: golint
|
||||
ctx = context.WithValue(ctx, "api-version", apiVersion)
|
||||
ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion)
|
||||
return handler(ctx, w, r, vars)
|
||||
}
|
||||
|
||||
|
||||
@@ -485,10 +485,7 @@ func (s *fsCacheStore) delete(id string) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.fs.Remove(src.BackendID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return s.fs.Remove(src.BackendID)
|
||||
}
|
||||
|
||||
type sourceMeta struct {
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
memdbContainersTable = "containers"
|
||||
memdbNamesTable = "names"
|
||||
|
||||
memdbContainersTable = "containers"
|
||||
memdbNamesTable = "names"
|
||||
memdbIDIndex = "id"
|
||||
memdbContainerIDIndex = "containerid"
|
||||
)
|
||||
@@ -191,11 +190,7 @@ func (db *memDB) ReserveName(name, containerID string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := txn.Insert(memdbNamesTable, nameAssociation{name: name, containerID: containerID}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return txn.Insert(memdbNamesTable, nameAssociation{name: name, containerID: containerID})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -262,11 +262,7 @@ func (c *containerAdapter) create(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.backend.UpdateContainerServiceConfig(cr.ID, c.container.serviceConfig()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return c.backend.UpdateContainerServiceConfig(cr.ID, c.container.serviceConfig())
|
||||
}
|
||||
|
||||
// checkMounts ensures that the provided mounts won't have any host-specific
|
||||
|
||||
@@ -511,11 +511,7 @@ func Validate(config *Config) error {
|
||||
}
|
||||
|
||||
// validate platform-specific settings
|
||||
if err := config.ValidatePlatformConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return config.ValidatePlatformConfig()
|
||||
}
|
||||
|
||||
// ModifiedDiscoverySettings returns whether the discovery configuration has been modified or not.
|
||||
|
||||
@@ -1046,11 +1046,7 @@ func (daemon *Daemon) Shutdown() error {
|
||||
daemon.netController.Stop()
|
||||
}
|
||||
|
||||
if err := daemon.cleanupMounts(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.cleanupMounts()
|
||||
}
|
||||
|
||||
// Mount sets container.BaseFS
|
||||
|
||||
@@ -1501,10 +1501,7 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
|
||||
if err := maybeCreateCPURealTimeFile(sysinfo.CPURealtimePeriod, daemon.configStore.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := maybeCreateCPURealTimeFile(sysinfo.CPURealtimeRuntime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return maybeCreateCPURealTimeFile(sysinfo.CPURealtimeRuntime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path)
|
||||
}
|
||||
|
||||
func maybeCreateCPURealTimeFile(sysinfoPresent bool, configValue int64, file string, path string) error {
|
||||
|
||||
@@ -579,10 +579,7 @@ func (a *Driver) unmount(mountPath string) error {
|
||||
if mounted, err := a.mounted(mountPath); err != nil || !mounted {
|
||||
return err
|
||||
}
|
||||
if err := Unmount(mountPath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return Unmount(mountPath)
|
||||
}
|
||||
|
||||
func (a *Driver) mounted(mountpoint string) (bool, error) {
|
||||
|
||||
@@ -14,8 +14,5 @@ func Unmount(target string) error {
|
||||
if err := exec.Command("auplink", target, "flush").Run(); err != nil {
|
||||
logrus.Warnf("Couldn't run auplink before unmount %s: %s", target, err)
|
||||
}
|
||||
if err := unix.Unmount(target, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return unix.Unmount(target, 0)
|
||||
}
|
||||
|
||||
@@ -598,16 +598,10 @@ func (d *Driver) setStorageSize(dir string, driver *Driver) error {
|
||||
if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {
|
||||
return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace)))
|
||||
}
|
||||
|
||||
if err := d.subvolEnableQuota(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := subvolLimitQgroup(dir, driver.options.size); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return subvolLimitQgroup(dir, driver.options.size)
|
||||
}
|
||||
|
||||
// Remove the filesystem with given id.
|
||||
@@ -634,10 +628,7 @@ func (d *Driver) Remove(id string) error {
|
||||
if err := system.EnsureRemoveAll(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.subvolRescanQuota(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return d.subvolRescanQuota()
|
||||
}
|
||||
|
||||
// Get the requested filesystem id.
|
||||
|
||||
@@ -273,8 +273,5 @@ func doCopyXattrs(srcPath, dstPath string) error {
|
||||
// this function is used to copy those. It is set by overlay if a directory
|
||||
// is removed and then re-created and should not inherit anything from the
|
||||
// same dir in the lower dir.
|
||||
if err := copyXattr(srcPath, dstPath, "trusted.overlay.opaque"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return copyXattr(srcPath, dstPath, "trusted.overlay.opaque")
|
||||
}
|
||||
|
||||
@@ -129,15 +129,10 @@ func verifyBlockDevice(dev string, force bool) error {
|
||||
if err := checkDevInVG(dev); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if force {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := checkDevHasFS(dev); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return checkDevHasFS(dev)
|
||||
}
|
||||
|
||||
func readLVMConfig(root string) (directLVMConfig, error) {
|
||||
|
||||
@@ -355,10 +355,7 @@ func (devices *DeviceSet) saveMetadata(info *devInfo) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("devmapper: Error encoding metadata to json: %s", err)
|
||||
}
|
||||
if err := devices.writeMetaFile(jsonData, devices.metadataFile(info)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return devices.writeMetaFile(jsonData, devices.metadataFile(info))
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) markDeviceIDUsed(deviceID int) {
|
||||
@@ -889,11 +886,7 @@ func (devices *DeviceSet) takeSnapshot(hash string, baseInfo *devInfo, size uint
|
||||
defer devicemapper.ResumeDevice(baseInfo.Name())
|
||||
}
|
||||
|
||||
if err = devices.createRegisterSnapDevice(hash, baseInfo, size); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.createRegisterSnapDevice(hash, baseInfo, size)
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *devInfo, size uint64) error {
|
||||
@@ -1233,12 +1226,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
||||
if err := devices.setupVerifyBaseImageUUIDFS(oldInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := devices.checkGrowBaseDeviceFS(oldInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.checkGrowBaseDeviceFS(oldInfo)
|
||||
}
|
||||
|
||||
logrus.Debug("devmapper: Removing uninitialized base image")
|
||||
@@ -1259,11 +1247,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
||||
}
|
||||
|
||||
// Create new base image device
|
||||
if err := devices.createBaseImage(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.createBaseImage()
|
||||
}
|
||||
|
||||
func setCloseOnExec(name string) {
|
||||
@@ -2082,11 +2066,7 @@ func (devices *DeviceSet) deleteDevice(info *devInfo, syncDelete bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := devices.deleteTransaction(info, syncDelete); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.deleteTransaction(info, syncDelete)
|
||||
}
|
||||
|
||||
// DeleteDevice will return success if device has been marked for deferred
|
||||
|
||||
@@ -146,12 +146,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
||||
if opts != nil {
|
||||
storageOpt = opts.StorageOpt
|
||||
}
|
||||
|
||||
if err := d.DeviceSet.AddDevice(id, parent, storageOpt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return d.DeviceSet.AddDevice(id, parent, storageOpt)
|
||||
}
|
||||
|
||||
// Remove removes a device with a given id, unmounts the filesystem.
|
||||
|
||||
@@ -263,11 +263,7 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
|
||||
if err := driver.WriteFile(root, root.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := driver.WriteFile(root, root.Join(layerDir, "parent-id"), []byte(parent), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return driver.WriteFile(root, root.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
||||
}
|
||||
|
||||
func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) {
|
||||
|
||||
@@ -309,10 +309,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr
|
||||
if err := idtools.MkdirAndChown(path.Join(dir, "work"), 0700, root); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(path.Join(dir, "lower-id"), []byte(parent), 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return ioutil.WriteFile(path.Join(dir, "lower-id"), []byte(parent), 0666)
|
||||
}
|
||||
|
||||
// Otherwise, copy the upper and the lower-id from the parent
|
||||
|
||||
@@ -14,12 +14,7 @@ func (daemon *Daemon) ContainerPause(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := daemon.containerPause(container); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.containerPause(container)
|
||||
}
|
||||
|
||||
// containerPause pauses the container execution without stopping the process.
|
||||
|
||||
@@ -90,11 +90,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
||||
return validationError{err}
|
||||
}
|
||||
}
|
||||
|
||||
if err := daemon.containerStart(container, checkpoint, checkpointDir, true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return daemon.containerStart(container, checkpoint, checkpointDir, true)
|
||||
}
|
||||
|
||||
// containerStart prepares the container to run by setting up everything the
|
||||
|
||||
@@ -14,12 +14,7 @@ func (daemon *Daemon) ContainerUnpause(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := daemon.containerUnpause(container); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.containerUnpause(container)
|
||||
}
|
||||
|
||||
// containerUnpause resumes the container execution after the container is paused.
|
||||
|
||||
@@ -133,10 +133,7 @@ func (s *fs) Delete(dgst digest.Digest) error {
|
||||
if err := os.RemoveAll(s.metadataDir(dgst)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Remove(s.contentFile(dgst)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Remove(s.contentFile(dgst))
|
||||
}
|
||||
|
||||
// SetMetadata sets metadata for a given ID. It fails if there's no base file.
|
||||
|
||||
@@ -348,11 +348,7 @@ func (d *Daemon) Kill() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
|
||||
}
|
||||
|
||||
// Pid returns the pid of the daemon
|
||||
@@ -459,11 +455,7 @@ out2:
|
||||
|
||||
d.cmd.Wait()
|
||||
|
||||
if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
|
||||
}
|
||||
|
||||
// Restart will restart the daemon by first stopping it and the starting it.
|
||||
|
||||
@@ -460,6 +460,7 @@ COPY file /file`
|
||||
assert.Equal(c, http.StatusOK, res.StatusCode)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
require.NoError(c, err)
|
||||
|
||||
ids := getImageIDsFromBuild(c, out)
|
||||
return ids[len(ids)-1]
|
||||
@@ -498,6 +499,7 @@ ADD file /file`
|
||||
assert.Equal(c, http.StatusOK, res.StatusCode)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
require.NoError(c, err)
|
||||
|
||||
ids := getImageIDsFromBuild(c, out)
|
||||
return ids[len(ids)-1]
|
||||
|
||||
@@ -328,9 +328,8 @@ func createNetwork(c *check.C, config types.NetworkCreateRequest, expectedStatus
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
return nr.ID
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func connectNetwork(c *check.C, nid, cid string) {
|
||||
|
||||
@@ -1031,7 +1031,7 @@ func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) {
|
||||
v := url.Values{}
|
||||
v.Set("scope", "local")
|
||||
|
||||
status, body, err = d.SockRequest("GET", "/networks/"+name+"?"+v.Encode(), nil)
|
||||
status, _, err = d.SockRequest("GET", "/networks/"+name+"?"+v.Encode(), nil)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf(string(out)))
|
||||
}
|
||||
|
||||
@@ -467,9 +467,8 @@ func (s *DockerDaemonSuite) TestDaemonIPv6HostMode(c *check.C) {
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Could not run container: %s, %v", out, err))
|
||||
|
||||
out, err = s.d.Cmd("exec", "hostcnt", "ip", "-6", "addr", "show", "docker0")
|
||||
out = strings.Trim(out, " \r\n'")
|
||||
|
||||
c.Assert(out, checker.Contains, "2001:db8:2::1")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.Trim(out, " \r\n'"), checker.Contains, "2001:db8:2::1")
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
|
||||
|
||||
@@ -153,10 +153,7 @@ func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := driver.WriteFile(root, fullPath, tf.content, tf.permission); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return driver.WriteFile(root, fullPath, tf.content, tf.permission)
|
||||
}
|
||||
|
||||
func initWithFiles(files ...FileApplier) layerInit {
|
||||
|
||||
@@ -68,11 +68,7 @@ func (ls *layerStore) CreateRWLayerByGraphID(name string, graphID string, parent
|
||||
m.initID = initID
|
||||
}
|
||||
|
||||
if err = ls.saveMount(m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return ls.saveMount(m)
|
||||
}
|
||||
|
||||
func (ls *layerStore) ChecksumForGraphID(id, parent, oldTarDataPath, newTarDataPath string) (diffID DiffID, size int64, err error) {
|
||||
|
||||
@@ -143,11 +143,7 @@ func storeLayer(tx MetadataTransaction, layer *roLayer) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tx.SetOS(layer.os); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return tx.SetOS(layer.os)
|
||||
}
|
||||
|
||||
func newVerifiedReadCloser(rc io.ReadCloser, dgst digest.Digest) (io.ReadCloser, error) {
|
||||
|
||||
@@ -89,11 +89,7 @@ func Migrate(root, driverName string, ls layer.Store, is image.Store, rs refstor
|
||||
return err
|
||||
}
|
||||
|
||||
if err := migrateRefs(root, driverName, rs, mappings); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return migrateRefs(root, driverName, rs, mappings)
|
||||
}
|
||||
|
||||
// CalculateLayerChecksums walks an old graph directory and calculates checksums
|
||||
|
||||
@@ -323,10 +323,7 @@ func addContainer(dest, jsonConfig string) error {
|
||||
if err := os.MkdirAll(contDir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(contDir, "config.json"), []byte(jsonConfig), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return ioutil.WriteFile(filepath.Join(contDir, "config.json"), []byte(jsonConfig), 0600)
|
||||
}
|
||||
|
||||
type mockTagAdder struct {
|
||||
|
||||
@@ -27,9 +27,5 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
}
|
||||
|
||||
// Take platform specific action for setting create time.
|
||||
if err := setCTime(name, mtime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return setCTime(name, mtime)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user