github.com/cdoern/storage@v1.12.13/pkg/idtools/utils_unix.go (about)

     1  // +build !windows
     2  
     3  package idtools
     4  
     5  import (
     6  	"fmt"
     7  	"os/exec"
     8  	"path/filepath"
     9  	"strings"
    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, args string) ([]byte, error) {
    30  	execCmd := exec.Command(cmd, strings.Split(args, " ")...)
    31  	return execCmd.CombinedOutput()
    32  }