invoke: Enable plugin file names with extensions
A CNI network configuration file contains the plugin's executable file name. Some platforms like Windows require a file name extension for executables. This causes unnecessary burden on admins as they now have to maintain two versions of each type of netconfig file, which differ only by the ".exe" extension. A much simpler design is for invoke package to also look for well-known extensions on platforms that require it. Existing tests are improved and new tests are added to cover the new behavior. Fixes #360
This commit is contained in:
@ -30,18 +30,14 @@ func FindInPath(plugin string, paths []string) (string, error) {
|
||||
return "", fmt.Errorf("no paths provided")
|
||||
}
|
||||
|
||||
var fullpath string
|
||||
for _, path := range paths {
|
||||
full := filepath.Join(path, plugin)
|
||||
if fi, err := os.Stat(full); err == nil && fi.Mode().IsRegular() {
|
||||
fullpath = full
|
||||
break
|
||||
for _, fe := range ExecutableFileExtensions {
|
||||
fullpath := filepath.Join(path, plugin) + fe
|
||||
if fi, err := os.Stat(fullpath); err == nil && fi.Mode().IsRegular() {
|
||||
return fullpath, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if fullpath == "" {
|
||||
return "", fmt.Errorf("failed to find plugin %q in path %s", plugin, paths)
|
||||
}
|
||||
|
||||
return fullpath, nil
|
||||
return "", fmt.Errorf("failed to find plugin %q in path %s", plugin, paths)
|
||||
}
|
||||
|
Reference in New Issue
Block a user