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

Function canExecProbably

pkg/platformutil/binfmt.go:45–77  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

43}
44
45func canExecProbably(s string) (bool, error) {
46 if s == "" {
47 return true, nil
48 }
49 p, err := platforms.Parse(s)
50 if err != nil {
51 return false, err
52 }
53 if platforms.Default().Match(p) {
54 return true, nil
55 }
56 if runtime.GOOS == "linux" {
57 qemuArch, err := qemuArchFromOCIArch(p.Architecture)
58 if err != nil {
59 return false, err
60 }
61 candidates := []string{
62 "/proc/sys/fs/binfmt_misc/qemu-" + qemuArch,
63 "/proc/sys/fs/binfmt_misc/buildkit-qemu-" + qemuArch,
64 }
65 // Rosetta 2 for Linux on ARM Mac
66 // https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta
67 if runtime.GOARCH == "arm64" && p.Architecture == "amd64" {
68 candidates = append(candidates, "/proc/sys/fs/binfmt_misc/rosetta")
69 }
70 for _, cand := range candidates {
71 if _, err := os.Stat(cand); err == nil {
72 return true, nil
73 }
74 }
75 }
76 return false, nil
77}
78
79func CanExecProbably(ss ...string) (bool, error) {
80 for _, s := range ss {

Callers 1

CanExecProbablyFunction · 0.85

Calls 3

qemuArchFromOCIArchFunction · 0.85
StatMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…