diff --git a/cmd/moby/build.go b/cmd/moby/build.go index 00eac6f57..405330260 100644 --- a/cmd/moby/build.go +++ b/cmd/moby/build.go @@ -25,7 +25,7 @@ func (f *formatList) String() string { } func (f *formatList) Set(value string) error { - // allow comma seperated options or multiple options + // allow comma separated options or multiple options for _, cs := range strings.Split(value, ",") { *f = append(*f, cs) } diff --git a/gometalinter.json b/gometalinter.json index dc6112639..39347e5e3 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -4,6 +4,7 @@ "Sort": ["linter", "severity", "path", "line"], "EnableGC": true, "WarnUnmatchedDirective": true, + "Exclude": ["parameter .* always receives"], "DisableAll": true, "Enable": [ diff --git a/src/initrd/initrd.go b/src/initrd/initrd.go index 31f987de6..d479fdf42 100644 --- a/src/initrd/initrd.go +++ b/src/initrd/initrd.go @@ -55,7 +55,7 @@ func typeconv(thdr *tar.Header) int64 { } } -func copyTarEntry(w *Writer, thdr *tar.Header, r *tar.Reader) (written int64, err error) { +func copyTarEntry(w *Writer, thdr *tar.Header, r io.Reader) (written int64, err error) { tp := typeconv(thdr) if tp == -1 { return written, errors.New("cannot convert tar file") diff --git a/src/moby/build.go b/src/moby/build.go index ef8e60ea7..7d3358323 100644 --- a/src/moby/build.go +++ b/src/moby/build.go @@ -18,8 +18,6 @@ import ( "gopkg.in/yaml.v2" ) -const defaultNameForStdin = "moby" - var streamable = map[string]bool{ "docker": true, "tar": true, diff --git a/src/moby/config.go b/src/moby/config.go index 49172574e..df3032675 100644 --- a/src/moby/config.go +++ b/src/moby/config.go @@ -197,7 +197,7 @@ func extractReferences(m *Moby) error { return nil } -func updateImages(m *Moby) error { +func updateImages(m *Moby) { if m.Kernel.ref != nil { m.Kernel.Image = m.Kernel.ref.String() } @@ -219,7 +219,6 @@ func updateImages(m *Moby) error { image.Image = image.ref.String() } } - return nil } // NewConfig parses a config file @@ -295,11 +294,7 @@ func AppendConfig(m0, m1 Moby) (Moby, error) { moby.Trust.Org = append(moby.Trust.Org, m1.Trust.Org...) moby.initRefs = append(moby.initRefs, m1.initRefs...) - if err := uniqueServices(moby); err != nil { - return moby, err - } - - return moby, nil + return moby, uniqueServices(moby) } // NewImage validates an parses yaml or json for a Image @@ -433,17 +428,6 @@ func assignBool(v1, v2 *bool) bool { return false } -// assignBoolPtr does ordered overrides from JSON bool pointers -func assignBoolPtr(v1, v2 *bool) *bool { - if v2 != nil { - return v2 - } - if v1 != nil { - return v1 - } - return nil -} - // assignIntPtr does ordered overrides from JSON int pointers func assignIntPtr(v1, v2 *int) *int { if v2 != nil { @@ -455,28 +439,6 @@ func assignIntPtr(v1, v2 *int) *int { return nil } -// assignUint32 does ordered overrides from JSON uint32 pointers -func assignUint32(v1, v2 *uint32) uint32 { - if v2 != nil { - return *v2 - } - if v1 != nil { - return *v1 - } - return 0 -} - -// assignUint32Array does ordered overrides from JSON uint32 array pointers -func assignUint32Array(v1, v2 *[]uint32) []uint32 { - if v2 != nil { - return *v2 - } - if v1 != nil { - return *v1 - } - return []uint32{} -} - // assignInterface does ordered overrides from Go interfaces // we return 0 as we are using this for uid and this is the default func assignInterface(v1, v2 *interface{}) interface{} { diff --git a/src/moby/image.go b/src/moby/image.go index 350c3730f..e60b25556 100644 --- a/src/moby/image.go +++ b/src/moby/image.go @@ -192,7 +192,7 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, trust bool, pull } // ImageBundle produces an OCI bundle at the given path in a tarball, given an image and a config.json -func ImageBundle(prefix string, ref *reference.Spec, config []byte, runtime Runtime, tw tarWriter, trust bool, pull bool, readonly bool, dupMap map[string]string) error { +func ImageBundle(prefix string, ref *reference.Spec, config []byte, runtime Runtime, tw tarWriter, trust bool, pull bool, readonly bool, dupMap map[string]string) error { // nolint: lll // if read only, just unpack in rootfs/ but otherwise set up for overlay rootExtract := "rootfs" if !readonly { diff --git a/src/moby/linuxkit.go b/src/moby/linuxkit.go index 8f5995e1b..fcc6efa42 100644 --- a/src/moby/linuxkit.go +++ b/src/moby/linuxkit.go @@ -65,12 +65,7 @@ func ensureLinuxkitImage(name string) error { if err != nil { return fmt.Errorf("Error converting to initrd: %v", err) } - err = writeKernelInitrd(filename, kernel, initrd, cmdline) - if err != nil { - return err - } - - return nil + return writeKernelInitrd(filename, kernel, initrd, cmdline) } func writeKernelInitrd(filename string, kernel []byte, initrd []byte, cmdline string) error { @@ -82,11 +77,7 @@ func writeKernelInitrd(filename string, kernel []byte, initrd []byte, cmdline st if err != nil { return err } - err = ioutil.WriteFile(filename+"-cmdline", []byte(cmdline), 0600) - if err != nil { - return err - } - return nil + return ioutil.WriteFile(filename+"-cmdline", []byte(cmdline), 0600) } func outputLinuxKit(format string, filename string, kernel []byte, initrd []byte, cmdline string, size int) error { @@ -127,13 +118,14 @@ func outputLinuxKit(format string, filename string, kernel []byte, initrd []byte if err != nil { return fmt.Errorf("Cannot find linuxkit executable, needed to build %s output type: %v", format, err) } - commandLine := []string{"-q", "run", "qemu", "-disk", fmt.Sprintf("%s,size=%s,format=%s", filename, sizeString, format), "-disk", fmt.Sprintf("%s,format=raw", tardisk), "-kernel", imageFilename("mkimage")} + commandLine := []string{ + "-q", "run", "qemu", + "-disk", fmt.Sprintf("%s,size=%s,format=%s", filename, sizeString, format), + "-disk", fmt.Sprintf("%s,format=raw", tardisk), + "-kernel", imageFilename("mkimage"), + } log.Debugf("run %s: %v", linuxkit, commandLine) cmd := exec.Command(linuxkit, commandLine...) cmd.Stderr = os.Stderr - err = cmd.Run() - if err != nil { - return err - } - return nil + return cmd.Run() } diff --git a/src/moby/output.go b/src/moby/output.go index e0f800ab5..8c170ee6f 100644 --- a/src/moby/output.go +++ b/src/moby/output.go @@ -246,11 +246,7 @@ func tarInitrdKernel(kernel, initrd []byte, cmdline string) (*bytes.Buffer, erro if err != nil { return buf, err } - err = tw.Close() - if err != nil { - return buf, err - } - return buf, nil + return buf, tw.Close() } func outputImg(image, filename string, kernel []byte, initrd []byte, cmdline string) error { @@ -268,25 +264,6 @@ func outputImg(image, filename string, kernel []byte, initrd []byte, cmdline str return dockerRun(buf, output, true, image, cmdline) } -// this should replace the other version for types that can specify a size -func outputImgSize(image, filename string, kernel []byte, initrd []byte, cmdline string, size int) error { - log.Debugf("output img: %s %s size %d", image, filename, size) - log.Infof(" %s", filename) - buf, err := tarInitrdKernel(kernel, initrd, cmdline) - if err != nil { - return err - } - output, err := os.Create(filename) - if err != nil { - return err - } - defer output.Close() - if size == 0 { - return dockerRun(buf, output, true, image) - } - return dockerRun(buf, output, true, image, fmt.Sprintf("%dM", size)) -} - func outputIso(image, filename string, filesystem []byte) error { log.Debugf("output ISO: %s %s", image, filename) log.Infof(" %s", filename) @@ -320,11 +297,7 @@ func outputKernelInitrd(base string, kernel []byte, initrd []byte, cmdline strin if err != nil { return err } - err = ioutil.WriteFile(base+"-cmdline", []byte(cmdline), os.FileMode(0644)) - if err != nil { - return err - } - return nil + return ioutil.WriteFile(base+"-cmdline", []byte(cmdline), os.FileMode(0644)) } func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdline string) error {