浏览代码

Merge pull request #21218 from runcom/len-check-fix

daemon: update: check len inside public function
David Calavera 9 年之前
父节点
当前提交
a2039f117c
共有 3 个文件被更改,包括 7 次插入6 次删除
  1. 3 5
      builder/dockerfile/internals.go
  2. 3 0
      daemon/update.go
  3. 1 1
      registry/registry_test.go

+ 3 - 5
builder/dockerfile/internals.go

@@ -527,11 +527,9 @@ func (b *Builder) create() (string, error) {
 	b.tmpContainers[c.ID] = struct{}{}
 	b.tmpContainers[c.ID] = struct{}{}
 	fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID))
 	fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID))
 
 
-	if len(config.Cmd) > 0 {
-		// override the entry point that may have been picked up from the base image
-		if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd); err != nil {
-			return "", err
-		}
+	// override the entry point that may have been picked up from the base image
+	if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd); err != nil {
+		return "", err
 	}
 	}
 
 
 	return c.ID, nil
 	return c.ID, nil

+ 3 - 0
daemon/update.go

@@ -25,6 +25,9 @@ func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostCon
 
 
 // ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID.
 // ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID.
 func (daemon *Daemon) ContainerUpdateCmdOnBuild(cID string, cmd []string) error {
 func (daemon *Daemon) ContainerUpdateCmdOnBuild(cID string, cmd []string) error {
+	if len(cmd) == 0 {
+		return nil
+	}
 	c, err := daemon.GetContainer(cID)
 	c, err := daemon.GetContainer(cID)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 1 - 1
registry/registry_test.go

@@ -171,7 +171,7 @@ func TestGetRemoteImageJSON(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 	assertEqual(t, size, int64(154), "Expected size 154")
 	assertEqual(t, size, int64(154), "Expected size 154")
-	if len(json) <= 0 {
+	if len(json) == 0 {
 		t.Fatal("Expected non-empty json")
 		t.Fatal("Expected non-empty json")
 	}
 	}