containers / common

Location for shared common files in github.com/containers repos.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emit error when binary file not executable

baude opened this issue · comments

the FindBinaryHelper should emit an error if it finds the binary but it is not exectable instead of claiming it could not find it.

https://github.com/containers/common/blob/main/pkg/config/config.go#L1110

we'd need to duplicate the code from os/exec.LookPath since it ignores files that are not executable.

Would it help if we improve the error message, something like:

diff --git a/pkg/config/config.go b/pkg/config/config.go
index 2e352db4..318015f1 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -1146,9 +1146,13 @@ func (c *Config) FindHelperBinary(name string, searchPATH bool) (string, error)
                }
        }
        if searchPATH {
-               return exec.LookPath(name)
+               p, err := exec.LookPath(name)
+               if errors.Is(err, exec.ErrNotFound) {
+                       return "", fmt.Errorf("could not find %q in $PATH (the file might be present but not executable): %w", name, err)
+               }
+               return p, err
        }
-       configHint := "To resolve this error, set the helper_binaries_dir key in the `[engine]` section of containers.conf to the directory containing your helper binaries."
+       configHint := "To resolve this error, set the helper_binaries_dir key in the `[engine]` section of containers.conf to the directory containing your helper binaries and make sure the file has the executable bit set."
        if len(c.Engine.HelperBinariesDir.Get()) == 0 {
                return "", fmt.Errorf("could not find %q because there are no helper binary directories configured.  %s", name, configHint)
        }