Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #642 from wwitzel3/issue-580
Browse files Browse the repository at this point in the history
Fix plugins not loading on Windows
  • Loading branch information
wwitzel3 committed Feb 7, 2020
2 parents b815638 + efc9f48 commit c52a347
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/580-wwitzel3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where plugins would not load on Windows.
12 changes: 9 additions & 3 deletions pkg/plugin/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Config interface {
Home() string
// Fs is the afero filesystem
Fs() afero.Fs
// OS is the opertating system
OS() string
}

type defaultConfig struct {
Expand All @@ -42,6 +44,11 @@ var (

var _ Config = (*defaultConfig)(nil)

// OS returns the plugin config operating system
func (c *defaultConfig) OS() string {
return c.os
}

// PluginDirs returns the plugin directories. Current only works on macOS and Linux
// and not in a container.
func (c *defaultConfig) PluginDirs(home string) ([]string, error) {
Expand Down Expand Up @@ -106,7 +113,6 @@ func AvailablePlugins(config Config) ([]string, error) {
}

var list []string

for _, dir := range dirs {
_, err = config.Fs().Stat(dir)
if err != nil {
Expand All @@ -124,8 +130,8 @@ func AvailablePlugins(config Config) ([]string, error) {

for _, fi := range fis {
mode := fi.Mode()

if mode|64 == mode {
// Windows does not have unix style executable bits.
if mode|64 == mode || config.OS() == "windows" {
pluginPath := filepath.Join(dir, fi.Name())
list = append(list, pluginPath)
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/plugin/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func Test_AvailablePlugins(t *testing.T) {
homePath: filepath.Join("/home", "xdg_config_path"),
key: "xdg-config-home",
},
{
homePath: filepath.Join("/windows", "test"),
key: "windows-test",
},
}

for _, test := range tests {
Expand All @@ -104,6 +108,30 @@ func Test_AvailablePlugins(t *testing.T) {
}

switch test.key {
case "windows-test":
c.os = "windows"
configPath := filepath.Join(test.homePath, configDir, "plugins")
err := fs.MkdirAll(configPath, 0700)
require.NoError(t, err, "unable to create test home directory")

stagePlugin := func(t *testing.T, path string, name string, mode os.FileMode) {
p := filepath.Join(path, name)
err = afero.WriteFile(fs, p, []byte("guts"), mode)
require.NoError(t, err)
}

// Non-executable UNIX permissions but OS is Windows
stagePlugin(t, configPath, "a-plugin", 0600)
stagePlugin(t, configPath, "e-plugin", 0755)

got, err := AvailablePlugins(c)
require.NoError(t, err)

expected := []string{
filepath.Join(configPath, "a-plugin"),
filepath.Join(configPath, "e-plugin"),
}
assert.Equal(t, expected, got)
case "plugin-path":
c.os = "unix"
customPath := filepath.Join("/example", "test")
Expand Down

0 comments on commit c52a347

Please sign in to comment.