From d7f299886d2fab8ecf1f5befa9f9341acda27e21 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 19 Mar 2024 10:11:07 -0400 Subject: [PATCH] command: scrub metadata from version at install When installing plugins with the `packer plugins install --path' command, the metadata is now scrubbed from the file installed locally. This is as a protection against collisions in the versions, as metadata is meaningless for version comparison, so if two versions of the same plugin are installed, the precedence order between them is undefined. Therefore to avoid such collisions, we remove the metadata from the file name, that way if two successive versions of a plugin include metadata in the version, they won't coexist, and the last installed will be the only installed version locally. --- command/plugins_install.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/plugins_install.go b/command/plugins_install.go index a2711e4ec..4360de411 100644 --- a/command/plugins_install.go +++ b/command/plugins_install.go @@ -300,10 +300,16 @@ func (c *PluginsInstallCommand) InstallFromBinary(opts plugingetter.ListInstalla }}) } + // Remove metadata from plugin path + noMetaVersion := semver.Core().String() + if semver.Prerelease() != "" { + noMetaVersion = fmt.Sprintf("%s-%s", noMetaVersion, semver.Prerelease()) + } + outputPrefix := fmt.Sprintf( "packer-plugin-%s_v%s_%s", pluginIdentifier.Type, - semver.String(), + noMetaVersion, desc.APIVersion, ) binaryPath := filepath.Join(