From 0e025b4bb16c0d4cc6b3f0c040713d061b9b051a Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Wed, 16 Mar 2016 19:43:26 -0700 Subject: [PATCH] fix variables that werent being called Signed-off-by: Jessica Frazelle --- api/server/router/container/exec.go | 2 -- builder/dockerfile/builder.go | 3 +++ builder/dockerfile/parser/parser.go | 2 +- cliconfig/config_test.go | 15 +++++++++++---- daemon/daemon_unix.go | 7 ++----- daemon/graphdriver/overlay/overlay.go | 4 ++++ pkg/authorization/authz_unix_test.go | 2 +- pkg/directory/directory_test.go | 3 +++ pkg/directory/directory_windows.go | 7 ------- pkg/jsonlog/jsonlog_marshalling.go | 6 ++---- pkg/jsonlog/jsonlogbytes.go | 6 ++---- pkg/mount/sharedsubtree_linux.go | 3 +-- pkg/pools/pools_test.go | 3 +-- pkg/symlink/fs_windows.go | 3 +-- pkg/tarsum/tarsum_test.go | 8 ++++++++ 15 files changed, 40 insertions(+), 34 deletions(-) diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go index bc336f6039..e0c3e51dc7 100644 --- a/api/server/router/container/exec.go +++ b/api/server/router/container/exec.go @@ -103,8 +103,6 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr) stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout) } - } else { - outStream = w } // Now run the user process in container. diff --git a/builder/dockerfile/builder.go b/builder/dockerfile/builder.go index f961a6ab60..24b31a0f9b 100644 --- a/builder/dockerfile/builder.go +++ b/builder/dockerfile/builder.go @@ -142,6 +142,9 @@ func sanitizeRepoAndTags(names []string) ([]reference.Named, error) { if _, isTagged := ref.(reference.NamedTagged); !isTagged { ref, err = reference.WithTag(ref, reference.DefaultTag) + if err != nil { + return nil, err + } } nameWithTag := ref.String() diff --git a/builder/dockerfile/parser/parser.go b/builder/dockerfile/parser/parser.go index ce258c5653..d16683a756 100644 --- a/builder/dockerfile/parser/parser.go +++ b/builder/dockerfile/parser/parser.go @@ -136,7 +136,7 @@ func Parse(rwc io.Reader) (*Node, error) { } } if child == nil && line != "" { - line, child, err = parseLine(line) + _, child, err = parseLine(line) if err != nil { return nil, err } diff --git a/cliconfig/config_test.go b/cliconfig/config_test.go index 5ea6f4071c..30c1777007 100644 --- a/cliconfig/config_test.go +++ b/cliconfig/config_test.go @@ -378,12 +378,14 @@ func TestJsonWithPsFormat(t *testing.T) { // Save it and make sure it shows up in new form func saveConfigAndValidateNewFormat(t *testing.T, config *ConfigFile, homeFolder string) string { - err := config.Save() - if err != nil { + if err := config.Save(); err != nil { t.Fatalf("Failed to save: %q", err) } buf, err := ioutil.ReadFile(filepath.Join(homeFolder, ConfigFileName)) + if err != nil { + t.Fatal(err) + } if !strings.Contains(string(buf), `"auths":`) { t.Fatalf("Should have save in new form: %s", string(buf)) } @@ -487,6 +489,9 @@ func TestJsonSaveWithNoFile(t *testing.T) { t.Fatalf("Failed saving to file: %q", err) } buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName)) + if err != nil { + t.Fatal(err) + } expConfStr := `{ "auths": { "https://index.docker.io/v1/": { @@ -517,11 +522,13 @@ func TestLegacyJsonSaveWithNoFile(t *testing.T) { fn := filepath.Join(tmpHome, ConfigFileName) f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - err = config.SaveToWriter(f) - if err != nil { + if err = config.SaveToWriter(f); err != nil { t.Fatalf("Failed saving to file: %q", err) } buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName)) + if err != nil { + t.Fatal(err) + } expConfStr := `{ "auths": { diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 7cc5aed78b..37b6f22d4e 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -798,7 +798,6 @@ func parseRemappedRoot(usergrp string) (string, string, error) { } return "", "", fmt.Errorf("Error during %q user creation: %v", defaultRemappedID, err) } - userID = luser.Uid username = luser.Name if len(idparts) == 1 { // we only have a string username, and no group specified; look up gid from username as group @@ -824,11 +823,9 @@ func parseRemappedRoot(usergrp string) (string, string, error) { groupname = lgrp.Name } else { // not a number; attempt a lookup - group, err := user.LookupGroup(idparts[1]) - if err != nil { - return "", "", fmt.Errorf("Error during gid lookup for %q: %v", idparts[1], err) + if _, err := user.LookupGroup(idparts[1]); err != nil { + return "", "", fmt.Errorf("Error during groupname lookup for %q: %v", idparts[1], err) } - groupID = group.Gid groupname = idparts[1] } } diff --git a/daemon/graphdriver/overlay/overlay.go b/daemon/graphdriver/overlay/overlay.go index 59131bba08..fa9b06be6c 100644 --- a/daemon/graphdriver/overlay/overlay.go +++ b/daemon/graphdriver/overlay/overlay.go @@ -371,6 +371,10 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) { // chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a // user namespace requires this to move a directory from lower to upper. rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) + if err != nil { + return "", err + } + if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil { return "", err } diff --git a/pkg/authorization/authz_unix_test.go b/pkg/authorization/authz_unix_test.go index 7d673fe518..1c6dc8a125 100644 --- a/pkg/authorization/authz_unix_test.go +++ b/pkg/authorization/authz_unix_test.go @@ -241,7 +241,7 @@ func (t *authZPluginTestServer) start() { r.HandleFunc("/Plugin.Activate", t.activate) r.HandleFunc("/"+AuthZApiRequest, t.auth) r.HandleFunc("/"+AuthZApiResponse, t.auth) - t.listener, err = net.Listen("tcp", pluginAddress) + t.listener, _ = net.Listen("tcp", pluginAddress) server := http.Server{Handler: r, Addr: pluginAddress} server.Serve(l) } diff --git a/pkg/directory/directory_test.go b/pkg/directory/directory_test.go index 1b196b105b..4611062848 100644 --- a/pkg/directory/directory_test.go +++ b/pkg/directory/directory_test.go @@ -168,6 +168,9 @@ func TestMoveToSubdir(t *testing.T) { } // validate that the files were moved to the subdirectory infos, err := ioutil.ReadDir(subDir) + if err != nil { + t.Fatal(err) + } if len(infos) != 4 { t.Fatalf("Should be four files in the subdir after the migration: actual length: %d", len(infos)) } diff --git a/pkg/directory/directory_windows.go b/pkg/directory/directory_windows.go index 6d41777391..7a9f8cb68c 100644 --- a/pkg/directory/directory_windows.go +++ b/pkg/directory/directory_windows.go @@ -5,17 +5,10 @@ package directory import ( "os" "path/filepath" - - "github.com/docker/docker/pkg/longpath" ) // Size walks a directory tree and returns its total size in bytes. func Size(dir string) (size int64, err error) { - fixedPath, err := filepath.Abs(dir) - if err != nil { - return - } - fixedPath = longpath.AddPrefix(fixedPath) err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, e error) error { // Ignore directory sizes if fileInfo == nil { diff --git a/pkg/jsonlog/jsonlog_marshalling.go b/pkg/jsonlog/jsonlog_marshalling.go index 31b047e3e3..83ce684a8e 100644 --- a/pkg/jsonlog/jsonlog_marshalling.go +++ b/pkg/jsonlog/jsonlog_marshalling.go @@ -93,7 +93,7 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { ffjsonWriteJSONString(buf, mj.Log) } if len(mj.Stream) != 0 { - if first == true { + if first { first = false } else { buf.WriteString(`,`) @@ -101,9 +101,7 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { buf.WriteString(`"stream":`) ffjsonWriteJSONString(buf, mj.Stream) } - if first == true { - first = false - } else { + if !first { buf.WriteString(`,`) } buf.WriteString(`"time":`) diff --git a/pkg/jsonlog/jsonlogbytes.go b/pkg/jsonlog/jsonlogbytes.go index ff7aaf16e3..df522c0d66 100644 --- a/pkg/jsonlog/jsonlogbytes.go +++ b/pkg/jsonlog/jsonlogbytes.go @@ -39,7 +39,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error { ffjsonWriteJSONString(buf, mj.Stream) } if len(mj.RawAttrs) > 0 { - if first == true { + if first { first = false } else { buf.WriteString(`,`) @@ -47,9 +47,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error { buf.WriteString(`"attrs":`) buf.Write(mj.RawAttrs) } - if first == true { - first = false - } else { + if !first { buf.WriteString(`,`) } buf.WriteString(`"time":`) diff --git a/pkg/mount/sharedsubtree_linux.go b/pkg/mount/sharedsubtree_linux.go index 47303bbcb6..8ceec84bc6 100644 --- a/pkg/mount/sharedsubtree_linux.go +++ b/pkg/mount/sharedsubtree_linux.go @@ -61,8 +61,7 @@ func ensureMountedAs(mountPoint, options string) error { return err } } - mounted, err = Mounted(mountPoint) - if err != nil { + if _, err = Mounted(mountPoint); err != nil { return err } diff --git a/pkg/pools/pools_test.go b/pkg/pools/pools_test.go index 78689800b4..1661b780c9 100644 --- a/pkg/pools/pools_test.go +++ b/pkg/pools/pools_test.go @@ -112,8 +112,7 @@ func TestBufioWriterPoolPutAndGet(t *testing.T) { buf.Reset() BufioWriter32KPool.Put(writer) // Try to write something - written, err = writer.Write([]byte("barfoo")) - if err != nil { + if _, err = writer.Write([]byte("barfoo")); err != nil { t.Fatal(err) } // If we now try to flush it, it should panic (the writer is nil) diff --git a/pkg/symlink/fs_windows.go b/pkg/symlink/fs_windows.go index 70988a37e6..449fe56483 100644 --- a/pkg/symlink/fs_windows.go +++ b/pkg/symlink/fs_windows.go @@ -23,8 +23,7 @@ func toShort(path string) (string, error) { } if n > uint32(len(b)) { b = make([]uint16, n) - n, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))) - if err != nil { + if _, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))); err != nil { return "", err } } diff --git a/pkg/tarsum/tarsum_test.go b/pkg/tarsum/tarsum_test.go index 8962666052..54bec53fc9 100644 --- a/pkg/tarsum/tarsum_test.go +++ b/pkg/tarsum/tarsum_test.go @@ -560,6 +560,10 @@ func Benchmark9kTar(b *testing.B) { return } n, err := io.Copy(buf, fh) + if err != nil { + b.Error(err) + return + } fh.Close() reader := bytes.NewReader(buf.Bytes()) @@ -586,6 +590,10 @@ func Benchmark9kTarGzip(b *testing.B) { return } n, err := io.Copy(buf, fh) + if err != nil { + b.Error(err) + return + } fh.Close() reader := bytes.NewReader(buf.Bytes())