Skip to content

Commit

Permalink
Golint: remove redundant ifs
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jan 14, 2018
1 parent 63a0e88 commit b4a6313
Show file tree
Hide file tree
Showing 27 changed files with 35 additions and 161 deletions.
5 changes: 1 addition & 4 deletions builder/fscache/fscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions container/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
)

const (
memdbContainersTable = "containers"
memdbNamesTable = "names"

memdbContainersTable = "containers"
memdbNamesTable = "names"
memdbIDIndex = "id"
memdbContainerIDIndex = "containerid"
)
Expand Down Expand Up @@ -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})
})
}

Expand Down
6 changes: 1 addition & 5 deletions daemon/cluster/executor/container/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions daemon/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions daemon/graphdriver/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions daemon/graphdriver/aufs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 2 additions & 11 deletions daemon/graphdriver/btrfs/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions daemon/graphdriver/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
7 changes: 1 addition & 6 deletions daemon/graphdriver/devmapper/device_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 5 additions & 25 deletions daemon/graphdriver/devmapper/deviceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions daemon/graphdriver/devmapper/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions daemon/graphdriver/graphtest/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions daemon/graphdriver/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions daemon/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions daemon/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions image/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 2 additions & 10 deletions integration-cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions integration-cli/docker_api_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions layer/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions layer/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions layer/ro_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit b4a6313

Please sign in to comment.