executor_linux only do path resolution in the taskDir, not local

split out lookPathIn to show it's similarity to exec.LookPath
This commit is contained in:
Lang Martin 2019-05-10 11:33:35 -04:00
parent 3ae276cfd2
commit 99359d7fbe

View file

@ -791,6 +791,10 @@ func lookupTaskBin(command *ExecCommand) (string, error) {
return root, nil return root, nil
} }
if strings.Contains(bin, "/") {
return "", fmt.Errorf("file %s not found under path %s", bin, taskDir)
}
// Find the PATH // Find the PATH
path := "/usr/local/bin:/usr/bin:/bin" path := "/usr/local/bin:/usr/bin:/bin"
for _, e := range command.Env { for _, e := range command.Env {
@ -799,25 +803,25 @@ func lookupTaskBin(command *ExecCommand) (string, error) {
} }
} }
// Check the host PATH anchored inside the taskDir return lookPathIn(path, taskDir, bin)
if !strings.Contains(bin, "/") { }
for _, dir := range filepath.SplitList(path) {
if dir == "" { // lookPathIn looks for a file with PATH inside the directory root. Like exec.LookPath
// match unix shell behavior, empty path element == . func lookPathIn(path string, root string, bin string) (string, error) {
dir = "." // exec.LookPath(file string)
} for _, dir := range filepath.SplitList(path) {
for _, root := range []string{localDir, taskDir} { if dir == "" {
path := filepath.Join(root, dir, bin) // match unix shell behavior, empty path element == .
f, err := os.Stat(path) dir = "."
if err != nil { }
continue path := filepath.Join(root, dir, bin)
} f, err := os.Stat(path)
if m := f.Mode(); !m.IsDir() { if err != nil {
return path, nil continue
} }
} if m := f.Mode(); !m.IsDir() {
return path, nil
} }
} }
return "", fmt.Errorf("file %s not found under path %s", bin, root)
return "", fmt.Errorf("file %s not found under path %s", bin, taskDir)
} }