mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
move lookupTaskBin to executor_linux, for os dependency clarity
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/stats"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
shelpers "github.com/hashicorp/nomad/helper/stats"
|
||||
@@ -770,3 +771,43 @@ func cmdMounts(mounts []*drivers.MountConfig) []*lconfigs.Mount {
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// lookupTaskBin finds the file `bin` in taskDir/local, taskDir in that order, then performs
|
||||
// a PATH search inside taskDir. It returns an absolute path. See also executor.lookupBin
|
||||
func lookupTaskBin(taskDir string, bin string) (string, error) {
|
||||
// Check in the local directory
|
||||
localDir := filepath.Join(taskDir, allocdir.TaskLocal)
|
||||
local := filepath.Join(localDir, bin)
|
||||
if _, err := os.Stat(local); err == nil {
|
||||
return local, nil
|
||||
}
|
||||
|
||||
// Check at the root of the task's directory
|
||||
root := filepath.Join(taskDir, bin)
|
||||
if _, err := os.Stat(root); err == nil {
|
||||
return root, nil
|
||||
}
|
||||
|
||||
// Check the host PATH anchored inside the taskDir
|
||||
if !strings.Contains(bin, "/") {
|
||||
envPath := os.Getenv("PATH")
|
||||
for _, dir := range filepath.SplitList(envPath) {
|
||||
if dir == "" {
|
||||
// match unix shell behavior, empty path element == .
|
||||
dir = "."
|
||||
}
|
||||
for _, root := range []string{localDir, taskDir} {
|
||||
path := filepath.Join(root, dir, bin)
|
||||
f, err := os.Stat(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if m := f.Mode(); !m.IsDir() {
|
||||
return path, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("file %s not found under path %s", bin, taskDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user