Browse code

fix variables that werent being called

Signed-off-by: Jessica Frazelle <acidburn@docker.com>

Jessica Frazelle authored on 2016/03/17 11:43:26
Showing 15 changed files
... ...
@@ -103,8 +103,6 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
103 103
 			stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
104 104
 			stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
105 105
 		}
106
-	} else {
107
-		outStream = w
108 106
 	}
109 107
 
110 108
 	// Now run the user process in container.
... ...
@@ -142,6 +142,9 @@ func sanitizeRepoAndTags(names []string) ([]reference.Named, error) {
142 142
 
143 143
 		if _, isTagged := ref.(reference.NamedTagged); !isTagged {
144 144
 			ref, err = reference.WithTag(ref, reference.DefaultTag)
145
+			if err != nil {
146
+				return nil, err
147
+			}
145 148
 		}
146 149
 
147 150
 		nameWithTag := ref.String()
... ...
@@ -136,7 +136,7 @@ func Parse(rwc io.Reader) (*Node, error) {
136 136
 				}
137 137
 			}
138 138
 			if child == nil && line != "" {
139
-				line, child, err = parseLine(line)
139
+				_, child, err = parseLine(line)
140 140
 				if err != nil {
141 141
 					return nil, err
142 142
 				}
... ...
@@ -378,12 +378,14 @@ func TestJsonWithPsFormat(t *testing.T) {
378 378
 
379 379
 // Save it and make sure it shows up in new form
380 380
 func saveConfigAndValidateNewFormat(t *testing.T, config *ConfigFile, homeFolder string) string {
381
-	err := config.Save()
382
-	if err != nil {
381
+	if err := config.Save(); err != nil {
383 382
 		t.Fatalf("Failed to save: %q", err)
384 383
 	}
385 384
 
386 385
 	buf, err := ioutil.ReadFile(filepath.Join(homeFolder, ConfigFileName))
386
+	if err != nil {
387
+		t.Fatal(err)
388
+	}
387 389
 	if !strings.Contains(string(buf), `"auths":`) {
388 390
 		t.Fatalf("Should have save in new form: %s", string(buf))
389 391
 	}
... ...
@@ -487,6 +489,9 @@ func TestJsonSaveWithNoFile(t *testing.T) {
487 487
 		t.Fatalf("Failed saving to file: %q", err)
488 488
 	}
489 489
 	buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName))
490
+	if err != nil {
491
+		t.Fatal(err)
492
+	}
490 493
 	expConfStr := `{
491 494
 	"auths": {
492 495
 		"https://index.docker.io/v1/": {
... ...
@@ -517,11 +522,13 @@ func TestLegacyJsonSaveWithNoFile(t *testing.T) {
517 517
 
518 518
 	fn := filepath.Join(tmpHome, ConfigFileName)
519 519
 	f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
520
-	err = config.SaveToWriter(f)
521
-	if err != nil {
520
+	if err = config.SaveToWriter(f); err != nil {
522 521
 		t.Fatalf("Failed saving to file: %q", err)
523 522
 	}
524 523
 	buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName))
524
+	if err != nil {
525
+		t.Fatal(err)
526
+	}
525 527
 
526 528
 	expConfStr := `{
527 529
 	"auths": {
... ...
@@ -798,7 +798,6 @@ func parseRemappedRoot(usergrp string) (string, string, error) {
798 798
 			}
799 799
 			return "", "", fmt.Errorf("Error during %q user creation: %v", defaultRemappedID, err)
800 800
 		}
801
-		userID = luser.Uid
802 801
 		username = luser.Name
803 802
 		if len(idparts) == 1 {
804 803
 			// 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) {
824 824
 			groupname = lgrp.Name
825 825
 		} else {
826 826
 			// not a number; attempt a lookup
827
-			group, err := user.LookupGroup(idparts[1])
828
-			if err != nil {
829
-				return "", "", fmt.Errorf("Error during gid lookup for %q: %v", idparts[1], err)
827
+			if _, err := user.LookupGroup(idparts[1]); err != nil {
828
+				return "", "", fmt.Errorf("Error during groupname lookup for %q: %v", idparts[1], err)
830 829
 			}
831
-			groupID = group.Gid
832 830
 			groupname = idparts[1]
833 831
 		}
834 832
 	}
... ...
@@ -371,6 +371,10 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
371 371
 	// chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a
372 372
 	// user namespace requires this to move a directory from lower to upper.
373 373
 	rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
374
+	if err != nil {
375
+		return "", err
376
+	}
377
+
374 378
 	if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil {
375 379
 		return "", err
376 380
 	}
... ...
@@ -241,7 +241,7 @@ func (t *authZPluginTestServer) start() {
241 241
 	r.HandleFunc("/Plugin.Activate", t.activate)
242 242
 	r.HandleFunc("/"+AuthZApiRequest, t.auth)
243 243
 	r.HandleFunc("/"+AuthZApiResponse, t.auth)
244
-	t.listener, err = net.Listen("tcp", pluginAddress)
244
+	t.listener, _ = net.Listen("tcp", pluginAddress)
245 245
 	server := http.Server{Handler: r, Addr: pluginAddress}
246 246
 	server.Serve(l)
247 247
 }
... ...
@@ -168,6 +168,9 @@ func TestMoveToSubdir(t *testing.T) {
168 168
 	}
169 169
 	// validate that the files were moved to the subdirectory
170 170
 	infos, err := ioutil.ReadDir(subDir)
171
+	if err != nil {
172
+		t.Fatal(err)
173
+	}
171 174
 	if len(infos) != 4 {
172 175
 		t.Fatalf("Should be four files in the subdir after the migration: actual length: %d", len(infos))
173 176
 	}
... ...
@@ -5,17 +5,10 @@ package directory
5 5
 import (
6 6
 	"os"
7 7
 	"path/filepath"
8
-
9
-	"github.com/docker/docker/pkg/longpath"
10 8
 )
11 9
 
12 10
 // Size walks a directory tree and returns its total size in bytes.
13 11
 func Size(dir string) (size int64, err error) {
14
-	fixedPath, err := filepath.Abs(dir)
15
-	if err != nil {
16
-		return
17
-	}
18
-	fixedPath = longpath.AddPrefix(fixedPath)
19 12
 	err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, e error) error {
20 13
 		// Ignore directory sizes
21 14
 		if fileInfo == nil {
... ...
@@ -93,7 +93,7 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error {
93 93
 		ffjsonWriteJSONString(buf, mj.Log)
94 94
 	}
95 95
 	if len(mj.Stream) != 0 {
96
-		if first == true {
96
+		if first {
97 97
 			first = false
98 98
 		} else {
99 99
 			buf.WriteString(`,`)
... ...
@@ -101,9 +101,7 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error {
101 101
 		buf.WriteString(`"stream":`)
102 102
 		ffjsonWriteJSONString(buf, mj.Stream)
103 103
 	}
104
-	if first == true {
105
-		first = false
106
-	} else {
104
+	if !first {
107 105
 		buf.WriteString(`,`)
108 106
 	}
109 107
 	buf.WriteString(`"time":`)
... ...
@@ -39,7 +39,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error {
39 39
 		ffjsonWriteJSONString(buf, mj.Stream)
40 40
 	}
41 41
 	if len(mj.RawAttrs) > 0 {
42
-		if first == true {
42
+		if first {
43 43
 			first = false
44 44
 		} else {
45 45
 			buf.WriteString(`,`)
... ...
@@ -47,9 +47,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error {
47 47
 		buf.WriteString(`"attrs":`)
48 48
 		buf.Write(mj.RawAttrs)
49 49
 	}
50
-	if first == true {
51
-		first = false
52
-	} else {
50
+	if !first {
53 51
 		buf.WriteString(`,`)
54 52
 	}
55 53
 	buf.WriteString(`"time":`)
... ...
@@ -61,8 +61,7 @@ func ensureMountedAs(mountPoint, options string) error {
61 61
 			return err
62 62
 		}
63 63
 	}
64
-	mounted, err = Mounted(mountPoint)
65
-	if err != nil {
64
+	if _, err = Mounted(mountPoint); err != nil {
66 65
 		return err
67 66
 	}
68 67
 
... ...
@@ -112,8 +112,7 @@ func TestBufioWriterPoolPutAndGet(t *testing.T) {
112 112
 	buf.Reset()
113 113
 	BufioWriter32KPool.Put(writer)
114 114
 	// Try to write something
115
-	written, err = writer.Write([]byte("barfoo"))
116
-	if err != nil {
115
+	if _, err = writer.Write([]byte("barfoo")); err != nil {
117 116
 		t.Fatal(err)
118 117
 	}
119 118
 	// If we now try to flush it, it should panic (the writer is nil)
... ...
@@ -23,8 +23,7 @@ func toShort(path string) (string, error) {
23 23
 	}
24 24
 	if n > uint32(len(b)) {
25 25
 		b = make([]uint16, n)
26
-		n, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b)))
27
-		if err != nil {
26
+		if _, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))); err != nil {
28 27
 			return "", err
29 28
 		}
30 29
 	}
... ...
@@ -560,6 +560,10 @@ func Benchmark9kTar(b *testing.B) {
560 560
 		return
561 561
 	}
562 562
 	n, err := io.Copy(buf, fh)
563
+	if err != nil {
564
+		b.Error(err)
565
+		return
566
+	}
563 567
 	fh.Close()
564 568
 
565 569
 	reader := bytes.NewReader(buf.Bytes())
... ...
@@ -586,6 +590,10 @@ func Benchmark9kTarGzip(b *testing.B) {
586 586
 		return
587 587
 	}
588 588
 	n, err := io.Copy(buf, fh)
589
+	if err != nil {
590
+		b.Error(err)
591
+		return
592
+	}
589 593
 	fh.Close()
590 594
 
591 595
 	reader := bytes.NewReader(buf.Bytes())