From 3b8c2417fbeaf84c4fb35e30f4c1a32ffcb51a59 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:04:33 +0200 Subject: [PATCH 1/6] use fmt.Fprintf instead of fmt.Fprint fmt.Fprint does not allow format strings --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 33a0997b9c..43ff0ca24f 100644 --- a/commands.go +++ b/commands.go @@ -99,7 +99,7 @@ func (srv *Server) CmdLogin(stdin io.ReadCloser, stdout io.Writer, args ...strin } if err != nil { if err != io.EOF { - fmt.Fprint(stdout, "Read error: %v\n", err) + fmt.Fprintf(stdout, "Read error: %v\n", err) } break } From 5ecd940a594507075e6cee80aa70c258a9d850ca Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:08:32 +0200 Subject: [PATCH 2/6] remove dead code in CmdPush --- commands.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 43ff0ca24f..0475b09451 100644 --- a/commands.go +++ b/commands.go @@ -512,10 +512,9 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string return err } return nil - } else { - return err } - return nil + + return err } err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig) if err != nil { From 1fc55c2bb9bce1451d6199e8aaa23ef8baa0e46c Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:10:50 +0200 Subject: [PATCH 3/6] kill the right containers in runtime_test --- runtime_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime_test.go b/runtime_test.go index d8e160fc0e..6551c24dc4 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -21,10 +21,10 @@ func nuke(runtime *Runtime) error { var wg sync.WaitGroup for _, container := range runtime.List() { wg.Add(1) - go func() { - container.Kill() + go func(c *Container) { + c.Kill() wg.Add(-1) - }() + }(container) } wg.Wait() return os.RemoveAll(runtime.root) From cab31fd5128fbfcc2f1b44d3d643fe96a28c88fc Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:11:34 +0200 Subject: [PATCH 4/6] use wg.Done() isntead of wg.Add(-1) --- runtime_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime_test.go b/runtime_test.go index 6551c24dc4..67221273a2 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -23,7 +23,7 @@ func nuke(runtime *Runtime) error { wg.Add(1) go func(c *Container) { c.Kill() - wg.Add(-1) + wg.Done() }(container) } wg.Wait() From 22f1cc955dbf25132e69d126f8db0e5498bffbd2 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:18:23 +0200 Subject: [PATCH 5/6] replace unreachable returns with panics Not only is this a more common idiom, it'll make finding bugs easier, and it'll make porting to Go 1.1 easier. Go 1.1 will not require the final return or panic because it has a notion of terminating statements. --- container.go | 2 +- network.go | 2 +- utils.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/container.go b/container.go index adb1602162..872bbb000b 100644 --- a/container.go +++ b/container.go @@ -626,7 +626,7 @@ func (container *Container) WaitTimeout(timeout time.Duration) error { case <-done: return nil } - return nil + panic("unreachable") } func (container *Container) EnsureMounted() error { diff --git a/network.go b/network.go index c050609d16..e92a4e5400 100644 --- a/network.go +++ b/network.go @@ -184,7 +184,7 @@ func (alloc *PortAllocator) Release(port int) error { default: return errors.New("Too many ports have been released") } - return nil + panic("unreachable") } func newPortAllocator(start, end int) (*PortAllocator, error) { diff --git a/utils.go b/utils.go index e295239f7f..5ee84239b1 100644 --- a/utils.go +++ b/utils.go @@ -202,7 +202,7 @@ func (r *bufReader) Read(p []byte) (n int, err error) { } r.wait.Wait() } - return + panic("unreachable") } func (r *bufReader) Close() error { From 14d3880daf9bdfe52248b5b0548a5522161baf2c Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Wed, 3 Apr 2013 11:19:48 +0200 Subject: [PATCH 6/6] remove superfluous panic --- runtime_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime_test.go b/runtime_test.go index 67221273a2..d35432bda1 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -90,7 +90,6 @@ func newTestRuntime() (*Runtime, error) { return nil, err } if err := CopyDirectory(unitTestStoreBase, root); err != nil { - panic(err) return nil, err }