packer: use filepath for getting plugin basename

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.
pull/12984/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent a852434410
commit ec92d231bc

@ -9,7 +9,6 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
@ -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)

Loading…
Cancel
Save