File: utils_unix.go

package info (click to toggle)
golang-github-containers-storage 1.61.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,012 kB
  • sloc: sh: 636; ansic: 389; makefile: 109; awk: 12
file content (31 lines) | stat: -rw-r--r-- 734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build !windows

package idtools

import (
	"fmt"
	"os/exec"
	"path/filepath"
)

func resolveBinary(binname string) (string, error) {
	binaryPath, err := exec.LookPath(binname)
	if err != nil {
		return "", err
	}
	resolvedPath, err := filepath.EvalSymlinks(binaryPath)
	if err != nil {
		return "", err
	}
	// only return no error if the final resolved binary basename
	// matches what was searched for
	if filepath.Base(resolvedPath) == binname {
		return resolvedPath, nil
	}
	return "", fmt.Errorf("binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath)
}

func execCmd(cmd string, args ...string) ([]byte, error) {
	execCmd := exec.Command(cmd, args...)
	return execCmd.CombinedOutput()
}