github.com/rish1988/moby@v25.0.2+incompatible/pkg/idtools/utils_unix.go (about)

     1  //go:build !windows
     2  
     3  package idtools // import "github.com/docker/docker/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  }