From a96584fb5613106cd106087f7f841fd57ff98cff Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Thu, 27 Jul 2023 16:04:34 -0400 Subject: [PATCH] Update plugin discover logic When copying a plugin's checksum file (packer-plugin-*_SHA256SUM) installed by `packer plugins install` or `packer init` into a separate directory the file may be copied with the executable bit turned out. If unchanged after the copy, Packer would discover the checksum file as a possible plugin match and error when trying to execute describe on the plugin look a like. This change adds a checksum file test to the plugin matching logic. If the discovered plugin name is a checksum it is excluded from the discovered plugin list. --- packer/plugin.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packer/plugin.go b/packer/plugin.go index 1a6a0ab84..69f0b631c 100644 --- a/packer/plugin.go +++ b/packer/plugin.go @@ -20,6 +20,11 @@ import ( plugingetter "github.com/hashicorp/packer/packer/plugin-getter" ) +var defaultChecksummer = plugingetter.Checksummer{ + Type: "sha256", + Hash: sha256.New(), +} + // PluginConfig helps load and use packer plugins type PluginConfig struct { KnownPluginFolders []string @@ -227,6 +232,14 @@ func (c *PluginConfig) discoverSingle(glob string) (map[string]string, error) { continue } + if strings.Contains(strings.ToUpper(file), defaultChecksummer.FileExt()) { + log.Printf( + "[TRACE] Ignoring plugin match %s, which looks to be a checksum file", + match) + continue + + } + // If the filename has a ".", trim up to there if idx := strings.Index(file, ".exe"); idx >= 0 { file = file[:idx] @@ -383,7 +396,7 @@ func (c *PluginConfig) discoverInstalledComponents(path string) error { APIVersionMajor: pluginsdk.APIVersionMajor, APIVersionMinor: pluginsdk.APIVersionMinor, Checksummers: []plugingetter.Checksummer{ - {Type: "sha256", Hash: sha256.New()}, + defaultChecksummer, }, }