FindTarBinary returns a path to the tar binary and whether it is GNU tar.
()
| 27 | |
| 28 | // FindTarBinary returns a path to the tar binary and whether it is GNU tar. |
| 29 | func FindTarBinary() (string, bool, error) { |
| 30 | isGNU := func(exe string) bool { |
| 31 | v, err := exec.Command(exe, "--version").Output() |
| 32 | if err != nil { |
| 33 | log.L.Warnf("Failed to detect whether %q is GNU tar or not", exe) |
| 34 | return false |
| 35 | } |
| 36 | if !strings.Contains(string(v), "GNU tar") { |
| 37 | log.L.Warnf("%q does not seem GNU tar", exe) |
| 38 | return false |
| 39 | } |
| 40 | return true |
| 41 | } |
| 42 | if v := os.Getenv("TAR"); v != "" { |
| 43 | if exe, err := exec.LookPath(v); err == nil { |
| 44 | return exe, isGNU(exe), nil |
| 45 | } |
| 46 | } |
| 47 | if exe, err := exec.LookPath("gnutar"); err == nil { |
| 48 | return exe, true, nil |
| 49 | } |
| 50 | if exe, err := exec.LookPath("gtar"); err == nil { |
| 51 | return exe, true, nil |
| 52 | } |
| 53 | if exe, err := exec.LookPath("tar"); err == nil { |
| 54 | return exe, isGNU(exe), nil |
| 55 | } |
| 56 | return "", false, fmt.Errorf("failed to find `tar` binary") |
| 57 | } |
searching dependent graphs…