From 07b1aa822cc7b371ef5925940d8ea8cfb54de57e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Oct 2022 16:20:33 +0200 Subject: [PATCH 1/2] pkg/system: move GetExitCode() to pkg/idtools, and un-export This utility was only used in a single place, and had no external consumers. Move it to where it's used. Signed-off-by: Sebastiaan van Stijn --- pkg/idtools/idtools_unix.go | 15 ++++++++++++++- pkg/system/exitcode.go | 19 ------------------- 2 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 pkg/system/exitcode.go diff --git a/pkg/idtools/idtools_unix.go b/pkg/idtools/idtools_unix.go index 2758726cc2..0dc6119a19 100644 --- a/pkg/idtools/idtools_unix.go +++ b/pkg/idtools/idtools_unix.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "os/exec" "path/filepath" "strconv" "sync" @@ -199,7 +200,7 @@ func callGetent(database, key string) (io.Reader, error) { } out, err := execCmd(getentCmd, database, key) if err != nil { - exitCode, errC := system.GetExitCode(err) + exitCode, errC := getExitCode(err) if errC != nil { return nil, err } @@ -217,6 +218,18 @@ func callGetent(database, key string) (io.Reader, error) { return bytes.NewReader(out), nil } +// 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") +} + // setPermissions performs a chown/chmod only if the uid/gid don't match what's requested // Normally a Chown is a no-op if uid/gid match, but in some cases this can still cause an error, e.g. if the // dir is on an NFS share, so don't call chown unless we absolutely must. diff --git a/pkg/system/exitcode.go b/pkg/system/exitcode.go deleted file mode 100644 index 4ba8fe35bf..0000000000 --- a/pkg/system/exitcode.go +++ /dev/null @@ -1,19 +0,0 @@ -package system // import "github.com/docker/docker/pkg/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") -} From ab677c41ea215cbb2f81c15a6d8a7ba505aff05a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Oct 2022 16:21:04 +0200 Subject: [PATCH 2/2] pkg/system: unconvert Signed-off-by: Sebastiaan van Stijn --- pkg/system/stat_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/system/stat_windows.go b/pkg/system/stat_windows.go index b2456cb887..0ff3af2fa1 100644 --- a/pkg/system/stat_windows.go +++ b/pkg/system/stat_windows.go @@ -20,12 +20,12 @@ func (s StatT) Size() int64 { // Mode returns file's permission mode. func (s StatT) Mode() os.FileMode { - return os.FileMode(s.mode) + return s.mode } // Mtim returns file's last modification time. func (s StatT) Mtim() time.Time { - return time.Time(s.mtim) + return s.mtim } // Stat takes a path to a file and returns