Bladeren bron

Remove use of pkg/integration in pkg/idtools

This remove a dependency on `go-check` (and more) when using
`pkg/idtools`. `pkg/integration` should never be called from any other
package then `integration`.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Vincent Demeester 8 jaren geleden
bovenliggende
commit
acf7ce1aa0
4 gewijzigde bestanden met toevoegingen van 38 en 31 verwijderingen
  1. 1 2
      pkg/idtools/idtools_unix.go
  2. 2 28
      pkg/integration/cmd/command.go
  3. 2 1
      pkg/integration/utils.go
  4. 33 0
      pkg/system/exitcode.go

+ 1 - 2
pkg/idtools/idtools_unix.go

@@ -11,7 +11,6 @@ import (
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
-	"github.com/docker/docker/pkg/integration/cmd"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
 	"github.com/opencontainers/runc/libcontainer/user"
 	"github.com/opencontainers/runc/libcontainer/user"
 )
 )
@@ -187,7 +186,7 @@ func callGetent(args string) (io.Reader, error) {
 	}
 	}
 	out, err := execCmd(getentCmd, args)
 	out, err := execCmd(getentCmd, args)
 	if err != nil {
 	if err != nil {
-		exitCode, errC := cmd.GetExitCode(err)
+		exitCode, errC := system.GetExitCode(err)
 		if errC != nil {
 		if errC != nil {
 			return nil, err
 			return nil, err
 		}
 		}

+ 2 - 28
pkg/integration/cmd/command.go

@@ -9,9 +9,9 @@ import (
 	"runtime"
 	"runtime"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
-	"syscall"
 	"time"
 	"time"
 
 
+	"github.com/docker/docker/pkg/system"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
 
 
@@ -24,32 +24,6 @@ const (
 	None string = "<NOTHING>"
 	None string = "<NOTHING>"
 )
 )
 
 
-// GetExitCode returns the ExitStatus of the specified error if its type is
-// exec.ExitError, returns 0 and an error otherwise.
-func GetExitCode(err error) (int, error) {
-	exitCode := 0
-	if exiterr, ok := err.(*exec.ExitError); ok {
-		if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
-			return procExit.ExitStatus(), nil
-		}
-	}
-	return exitCode, fmt.Errorf("failed to get exit code")
-}
-
-// ProcessExitCode process the specified error and returns the exit status code
-// if the error was of type exec.ExitError, returns nothing otherwise.
-func ProcessExitCode(err error) (exitCode int) {
-	if err != nil {
-		var exiterr error
-		if exitCode, exiterr = GetExitCode(err); exiterr != nil {
-			// TODO: Fix this so we check the error's text.
-			// we've failed to retrieve exit code, so we set it to 127
-			exitCode = 127
-		}
-	}
-	return
-}
-
 type lockedBuffer struct {
 type lockedBuffer struct {
 	m   sync.RWMutex
 	m   sync.RWMutex
 	buf bytes.Buffer
 	buf bytes.Buffer
@@ -196,7 +170,7 @@ func (r *Result) SetExitError(err error) {
 		return
 		return
 	}
 	}
 	r.Error = err
 	r.Error = err
-	r.ExitCode = ProcessExitCode(err)
+	r.ExitCode = system.ProcessExitCode(err)
 }
 }
 
 
 type matches struct{}
 type matches struct{}

+ 2 - 1
pkg/integration/utils.go

@@ -15,6 +15,7 @@ import (
 
 
 	icmd "github.com/docker/docker/pkg/integration/cmd"
 	icmd "github.com/docker/docker/pkg/integration/cmd"
 	"github.com/docker/docker/pkg/stringutils"
 	"github.com/docker/docker/pkg/stringutils"
+	"github.com/docker/docker/pkg/system"
 )
 )
 
 
 // IsKilled process the specified error and returns whether the process was killed or not.
 // IsKilled process the specified error and returns whether the process was killed or not.
@@ -35,7 +36,7 @@ func IsKilled(err error) bool {
 func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
 func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
 	exitCode = 0
 	exitCode = 0
 	out, err := cmd.CombinedOutput()
 	out, err := cmd.CombinedOutput()
-	exitCode = icmd.ProcessExitCode(err)
+	exitCode = system.ProcessExitCode(err)
 	output = string(out)
 	output = string(out)
 	return
 	return
 }
 }

+ 33 - 0
pkg/system/exitcode.go

@@ -0,0 +1,33 @@
+package system
+
+import (
+	"fmt"
+	"os/exec"
+	"syscall"
+)
+
+// GetExitCode returns the ExitStatus of the specified error if its type is
+// exec.ExitError, returns 0 and an error otherwise.
+func GetExitCode(err error) (int, error) {
+	exitCode := 0
+	if exiterr, ok := err.(*exec.ExitError); ok {
+		if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
+			return procExit.ExitStatus(), nil
+		}
+	}
+	return exitCode, fmt.Errorf("failed to get exit code")
+}
+
+// ProcessExitCode process the specified error and returns the exit status code
+// if the error was of type exec.ExitError, returns nothing otherwise.
+func ProcessExitCode(err error) (exitCode int) {
+	if err != nil {
+		var exiterr error
+		if exitCode, exiterr = GetExitCode(err); exiterr != nil {
+			// TODO: Fix this so we check the error's text.
+			// we've failed to retrieve exit code, so we set it to 127
+			exitCode = 127
+		}
+	}
+	return
+}