mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
plugins: Load plugins on windows
This commit is contained in:
committed by
Danielle Tomlinson
parent
e9a7978367
commit
8547428807
@@ -6,6 +6,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"runtime"
|
||||
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
@@ -250,10 +251,15 @@ func (l *PluginLoader) scan() ([]os.FileInfo, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if it is executable by anyone
|
||||
if s.Mode().Perm()&0111 == 0 {
|
||||
l.logger.Debug("skipping un-executable file in plugin folder", "file", f)
|
||||
continue
|
||||
// Check if it is executable by anyone. On windows, an executable is any file with any
|
||||
// extension and the file begins with MZ, however, there is no easy way for us to
|
||||
// actually validate the executability of a file, so here we skip executability checks
|
||||
// for windows systems.
|
||||
if runtime.GOOS != "windows" {
|
||||
if s.Mode().Perm()&0111 == 0 {
|
||||
l.logger.Debug("skipping un-executable file in plugin folder", "file", f)
|
||||
continue
|
||||
}
|
||||
}
|
||||
plugins = append(plugins, s)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"runtime"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
version "github.com/hashicorp/go-version"
|
||||
@@ -55,8 +56,12 @@ func newHarness(t *testing.T, plugins []string) *harness {
|
||||
t.Fatalf("failed to get self executable path: %v", err)
|
||||
}
|
||||
|
||||
exeSuffix := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
exeSuffix = ".exe"
|
||||
}
|
||||
for _, p := range plugins {
|
||||
dest := filepath.Join(h.tmpDir, p)
|
||||
dest := strings.Join([]string{filepath.Join(h.tmpDir, p), exeSuffix}, "")
|
||||
if err := copyFile(selfExe, dest); err != nil {
|
||||
t.Fatalf("failed to copy file: %v", err)
|
||||
}
|
||||
@@ -1217,6 +1222,9 @@ func TestPluginLoader_Bad_Executable(t *testing.T) {
|
||||
|
||||
// Test that we skip directories, non-executables and follow symlinks
|
||||
func TestPluginLoader_External_SkipBadFiles(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("Windows currently does not skip non exe files")
|
||||
}
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user