Merge pull request #28925 from daehyeok/ineffassign

Refactoring ineffectual assignments
This commit is contained in:
Sebastiaan van Stijn 2017-01-18 15:01:57 +01:00 committed by GitHub
commit 5eda0c5947
12 changed files with 25 additions and 29 deletions

View File

@ -79,8 +79,8 @@ func ToParamWithVersion(version string, a Args) (string, error) {
} }
// for daemons older than v1.10, filter must be of the form map[string][]string // for daemons older than v1.10, filter must be of the form map[string][]string
buf := []byte{} var buf []byte
err := errors.New("") var err error
if version != "" && versions.LessThan(version, "1.22") { if version != "" && versions.LessThan(version, "1.22") {
buf, err = json.Marshal(convertArgsToSlice(a.fields)) buf, err = json.Marshal(convertArgsToSlice(a.fields))
} else { } else {

View File

@ -204,10 +204,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
name := args[0] name := args[0]
var ( var image builder.Image
image builder.Image
err error
)
// Windows cannot support a container with no base image. // Windows cannot support a container with no base image.
if name == api.NoBaseImageSpecifier { if name == api.NoBaseImageSpecifier {
@ -219,10 +216,11 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
} else { } else {
// TODO: don't use `name`, instead resolve it to a digest // TODO: don't use `name`, instead resolve it to a digest
if !b.options.PullParent { if !b.options.PullParent {
image, err = b.docker.GetImageOnBuild(name) image, _ = b.docker.GetImageOnBuild(name)
// TODO: shouldn't we error out if error is different from "not found" ? // TODO: shouldn't we error out if error is different from "not found" ?
} }
if image == nil { if image == nil {
var err error
image, err = b.docker.PullOnBuild(b.clientCtx, name, b.options.AuthConfigs, b.Output) image, err = b.docker.PullOnBuild(b.clientCtx, name, b.options.AuthConfigs, b.Output)
if err != nil { if err != nil {
return err return err

View File

@ -113,7 +113,6 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
var err error var err error
for _, orig := range args[0 : len(args)-1] { for _, orig := range args[0 : len(args)-1] {
var fi builder.FileInfo var fi builder.FileInfo
decompress := allowLocalDecompression
if urlutil.IsURL(orig) { if urlutil.IsURL(orig) {
if !allowRemote { if !allowRemote {
return fmt.Errorf("Source can't be a URL for %s", cmdName) return fmt.Errorf("Source can't be a URL for %s", cmdName)
@ -123,8 +122,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
return err return err
} }
defer os.RemoveAll(filepath.Dir(fi.Path())) defer os.RemoveAll(filepath.Dir(fi.Path()))
decompress = false infos = append(infos, copyInfo{
infos = append(infos, copyInfo{fi, decompress}) FileInfo: fi,
decompress: false,
})
continue continue
} }
// not a URL // not a URL

View File

@ -81,14 +81,11 @@ func collect(ctx context.Context, s *formatter.ContainerStats, cli client.APICli
go func() { go func() {
for { for {
var ( var (
v *types.StatsJSON v *types.StatsJSON
memPercent = 0.0 memPercent, cpuPercent float64
cpuPercent = 0.0 blkRead, blkWrite uint64 // Only used on Linux
blkRead, blkWrite uint64 // Only used on Linux mem, memLimit, memPerc float64
mem = 0.0 pidsStatsCurrent uint64
memLimit = 0.0
memPerc = 0.0
pidsStatsCurrent uint64
) )
if err := dec.Decode(&v); err != nil { if err := dec.Decode(&v); err != nil {

View File

@ -41,7 +41,9 @@ func validateConfig(path string) error {
// validateContextDir validates the given dir and returns abs path on success. // validateContextDir validates the given dir and returns abs path on success.
func validateContextDir(contextDir string) (string, error) { func validateContextDir(contextDir string) (string, error) {
absContextDir, err := filepath.Abs(contextDir) absContextDir, err := filepath.Abs(contextDir)
if err != nil {
return "", err
}
stat, err := os.Lstat(absContextDir) stat, err := os.Lstat(absContextDir)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -497,7 +497,7 @@ func UsingSystemd(config *Config) bool {
// verifyPlatformContainerSettings performs platform-specific validation of the // verifyPlatformContainerSettings performs platform-specific validation of the
// hostconfig and config structures. // hostconfig and config structures.
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
warnings := []string{} var warnings []string
sysInfo := sysinfo.New(true) sysInfo := sysinfo.New(true)
warnings, err := daemon.verifyExperimentalContainerSettings(hostConfig, config) warnings, err := daemon.verifyExperimentalContainerSettings(hostConfig, config)
@ -925,7 +925,6 @@ func parseRemappedRoot(usergrp string) (string, string, error) {
if err != nil { if err != nil {
return "", "", fmt.Errorf("Error during gid lookup for %q: %v", lookupName, err) return "", "", fmt.Errorf("Error during gid lookup for %q: %v", lookupName, err)
} }
groupID = group.Gid
groupname = group.Name groupname = group.Name
} }
} }

View File

@ -64,7 +64,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
s.Process.User.Username = c.Config.User s.Process.User.Username = c.Config.User
// In spec.Root. This is not set for Hyper-V containers // In spec.Root. This is not set for Hyper-V containers
isHyperV := false var isHyperV bool
if c.HostConfig.Isolation.IsDefault() { if c.HostConfig.Isolation.IsDefault() {
// Container using default isolation, so take the default from the daemon configuration // Container using default isolation, so take the default from the daemon configuration
isHyperV = daemon.defaultIsolation.IsHyperV() isHyperV = daemon.defaultIsolation.IsHyperV()

View File

@ -121,7 +121,7 @@ type v1DependencyImage struct {
func newV1DependencyImage(l layer.Layer, parent *v1DependencyImage) *v1DependencyImage { func newV1DependencyImage(l layer.Layer, parent *v1DependencyImage) *v1DependencyImage {
v1ID := digest.Digest(l.ChainID()).Hex() v1ID := digest.Digest(l.ChainID()).Hex()
config := "" var config string
if parent != nil { if parent != nil {
config = fmt.Sprintf(`{"id":"%s","parent":"%s"}`, v1ID, parent.V1ID()) config = fmt.Sprintf(`{"id":"%s","parent":"%s"}`, v1ID, parent.V1ID())
} else { } else {

View File

@ -29,7 +29,7 @@ type applyLayerResponse struct {
func applyLayer() { func applyLayer() {
var ( var (
tmpDir = "" tmpDir string
err error err error
options *archive.TarOptions options *archive.TarOptions
) )

View File

@ -35,7 +35,6 @@ func IsKilled(err error) bool {
} }
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) { func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
exitCode = 0
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
exitCode = system.ProcessExitCode(err) exitCode = system.ProcessExitCode(err)
output = string(out) output = string(out)

View File

@ -290,7 +290,7 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, imgSize int64) (io
if err != nil { if err != nil {
return nil, fmt.Errorf("Error while getting from the server: %v", err) return nil, fmt.Errorf("Error while getting from the server: %v", err)
} }
statusCode = 0
res, err = r.client.Do(req) res, err = r.client.Do(req)
if err != nil { if err != nil {
logrus.Debugf("Error contacting registry %s: %v", registry, err) logrus.Debugf("Error contacting registry %s: %v", registry, err)

View File

@ -200,12 +200,12 @@ func GetAllDrivers() ([]volume.Driver, error) {
for _, p := range plugins { for _, p := range plugins {
name := p.Name() name := p.Name()
ext, ok := drivers.extensions[name]
if ok { if _, ok := drivers.extensions[name]; ok {
continue continue
} }
ext = NewVolumeDriver(name, p.BasePath(), p.Client()) ext := NewVolumeDriver(name, p.BasePath(), p.Client())
if p.IsV1() { if p.IsV1() {
drivers.extensions[name] = ext drivers.extensions[name] = ext
} }