Skip to content

Commit

Permalink
packer: use filepath for getting plugin basename
Browse files Browse the repository at this point in the history
When Discovering plugins installed through the `Discover` function, we
use the base name of the plugin binary we discovered preliminarly, then
we match its name against a regex to extract the prefix for the plugin's
components.

Extracting the base path used to be done with `path.Base`, which while
working perfectly on UNIX systems, does not on Windows as it uses `\\`
as their path separator.

To circumvent this problem, we use the `filepath` package to extract the
base name of the plugin instead, making the discovery logic work again
on Windows.
  • Loading branch information
lbajolet-hashicorp committed May 16, 2024
1 parent a852434 commit ec92d23
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -103,7 +102,7 @@ func (c *PluginConfig) Discover() error {
// We'll use that later to register the components for each plugin
pluginMap := map[string]string{}
for _, install := range installations {
pluginBasename := path.Base(install.BinaryPath)
pluginBasename := filepath.Base(install.BinaryPath)
matches := extractPluginBasename.FindStringSubmatch(pluginBasename)
if len(matches) != 2 {
log.Printf("[INFO] - plugin %q could not have its name matched, ignoring", pluginBasename)
Expand Down

0 comments on commit ec92d23

Please sign in to comment.