github.com/rumpl/bof@v23.0.0-rc.2+incompatible/pkg/idtools/utils_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package idtools // import "github.com/docker/docker/pkg/idtools"
     5  
     6  import (
     7  	"fmt"
     8  	"os/exec"
     9  	"path/filepath"
    10  )
    11  
    12  func resolveBinary(binname string) (string, error) {
    13  	binaryPath, err := exec.LookPath(binname)
    14  	if err != nil {
    15  		return "", err
    16  	}
    17  	resolvedPath, err := filepath.EvalSymlinks(binaryPath)
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  	// only return no error if the final resolved binary basename
    22  	// matches what was searched for
    23  	if filepath.Base(resolvedPath) == binname {
    24  		return resolvedPath, nil
    25  	}
    26  	return "", fmt.Errorf("Binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath)
    27  }
    28  
    29  func execCmd(cmd string, arg ...string) ([]byte, error) {
    30  	execCmd := exec.Command(cmd, arg...)
    31  	return execCmd.CombinedOutput()
    32  }