Skip to content

Commit 1e465f8

Browse files
authored
fix: small tweaks for windows friendliness (#18)
1 parent a46d6c2 commit 1e465f8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pkg/plugins/config.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,24 @@ func (c *Config) providerOverride(provider proto.Provider) (string, string) {
107107
}
108108
}
109109

110+
// pluginBinaryName returns the binary filename for the given plugin name,
111+
// appending .exe on Windows where executables require the extension.
112+
func pluginBinaryName(name string) string {
113+
if runtime.GOOS == "windows" {
114+
return name + ".exe"
115+
}
116+
return name
117+
}
118+
110119
func (c *Config) Ensure(plugin, wantVersion string) (string, error) {
111120
logging.Debugf("ensuring plugin %q is available", plugin)
112121

113122
platform := runtime.GOOS + "_" + runtime.GOARCH
123+
binaryName := pluginBinaryName(plugin)
114124

115125
if len(wantVersion) > 0 {
116126
// The user has requested a specific version.
117-
want := filepath.Join(c.Cache, plugin, platform, wantVersion, plugin)
127+
want := filepath.Join(c.Cache, plugin, platform, wantVersion, binaryName)
118128
if _, err := os.Stat(want); err == nil {
119129
return want, nil
120130
}
@@ -123,7 +133,7 @@ func (c *Config) Ensure(plugin, wantVersion string) (string, error) {
123133
// When auto-update is disabled and the user hasn't picked a specific version, use the latest cached version if
124134
// available.
125135
if len(wantVersion) == 0 && !c.AutoUpdate {
126-
matches, _ := filepath.Glob(filepath.Join(c.Cache, plugin, platform, "*", plugin))
136+
matches, _ := filepath.Glob(filepath.Join(c.Cache, plugin, platform, "*", binaryName))
127137
if len(matches) > 0 {
128138
sort.Slice(matches, func(i, j int) bool {
129139
vi := "v" + filepath.Base(filepath.Dir(matches[i]))
@@ -162,7 +172,7 @@ func (c *Config) Ensure(plugin, wantVersion string) (string, error) {
162172
return "", fmt.Errorf("plugin %q version %q has no artifact for %s", plugin, wantVersion, platform)
163173
}
164174

165-
binaryPath := filepath.Join(c.Cache, plugin, platform, wantVersion, plugin)
175+
binaryPath := filepath.Join(c.Cache, plugin, platform, wantVersion, binaryName)
166176

167177
if _, err := os.Stat(binaryPath); err == nil {
168178
logging.Debugf("plugin %q already cached at %s", plugin, binaryPath)
@@ -188,7 +198,7 @@ func (c *Config) Ensure(plugin, wantVersion string) (string, error) {
188198
case strings.HasSuffix(artifact.Name, ".tar.gz"):
189199
err = unpackTarGz(archivePath, tmpBinary, plugin)
190200
case strings.HasSuffix(artifact.Name, ".zip"):
191-
err = unpackZip(archivePath, tmpBinary, plugin+".exe")
201+
err = unpackZip(archivePath, tmpBinary, binaryName)
192202
default:
193203
err = fmt.Errorf("unsupported archive format for %s", artifact.Name)
194204
}

pkg/plugins/providers/providers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"runtime"
89

910
"github.com/hashicorp/go-hclog"
1011
"github.com/hashicorp/go-plugin"
@@ -27,7 +28,7 @@ func Connect(path string, level hclog.Level) (proto.ProviderServiceClient, func(
2728
return nil, nil, fmt.Errorf("error accessing plugin path: %w", err)
2829
} else if stat.IsDir() {
2930
return nil, nil, fmt.Errorf("plugin path is a directory")
30-
} else if stat.Mode()&0111 == 0 {
31+
} else if runtime.GOOS != "windows" && stat.Mode()&0111 == 0 {
3132
return nil, nil, fmt.Errorf("plugin path is not executable")
3233
}
3334

0 commit comments

Comments
 (0)