utils_unix.go 668 B

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