github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/idtools/utils_unix.go (about) 1 //go:build !windows 2 3 package idtools // import "github.com/Prakhar-Agarwal-byte/moby/pkg/idtools" 4 5 import ( 6 "fmt" 7 "os/exec" 8 "path/filepath" 9 ) 10 11 func resolveBinary(binname string) (string, error) { 12 binaryPath, err := exec.LookPath(binname) 13 if err != nil { 14 return "", err 15 } 16 resolvedPath, err := filepath.EvalSymlinks(binaryPath) 17 if err != nil { 18 return "", err 19 } 20 // only return no error if the final resolved binary basename 21 // matches what was searched for 22 if filepath.Base(resolvedPath) == binname { 23 return resolvedPath, nil 24 } 25 return "", fmt.Errorf("Binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath) 26 }