MCPcopy Create free account
hub / github.com/containerd/nerdctl / FindTarBinary

Function FindTarBinary

pkg/tarutil/tarutil.go:29–57  ·  view source on GitHub ↗

FindTarBinary returns a path to the tar binary and whether it is GNU tar.

()

Source from the content-addressed store, hash-verified

27
28// FindTarBinary returns a path to the tar binary and whether it is GNU tar.
29func 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}

Callers 2

CopyFilesFunction · 0.92
cpTestHelperFunction · 0.92

Calls 1

CommandMethod · 0.65

Tested by 1

cpTestHelperFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…