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>
This commit is contained in:
Vincent Demeester 2016-11-08 17:21:02 +01:00
parent 189727581b
commit acf7ce1aa0
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
4 changed files with 38 additions and 31 deletions

View File

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

View File

@ -9,9 +9,9 @@ import (
"runtime"
"strings"
"sync"
"syscall"
"time"
"github.com/docker/docker/pkg/system"
"github.com/go-check/check"
)
@ -24,32 +24,6 @@ const (
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 {
m sync.RWMutex
buf bytes.Buffer
@ -196,7 +170,7 @@ func (r *Result) SetExitError(err error) {
return
}
r.Error = err
r.ExitCode = ProcessExitCode(err)
r.ExitCode = system.ProcessExitCode(err)
}
type matches struct{}

View File

@ -15,6 +15,7 @@ import (
icmd "github.com/docker/docker/pkg/integration/cmd"
"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.
@ -35,7 +36,7 @@ func IsKilled(err error) bool {
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
exitCode = 0
out, err := cmd.CombinedOutput()
exitCode = icmd.ProcessExitCode(err)
exitCode = system.ProcessExitCode(err)
output = string(out)
return
}

33
pkg/system/exitcode.go Normal file
View File

@ -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
}