From c40d96d0ab3e7780d9a8c5ef240fb5d9782f1885 Mon Sep 17 00:00:00 2001 From: Will Browne Date: Wed, 10 Mar 2021 19:13:08 +0100 Subject: [PATCH] Plugins: Remove pre-existing plugin installs when installing with grafana-cli (#31515) * remove old install before install if exists * fix log format --- pkg/cmd/grafana-cli/commands/install_command.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/cmd/grafana-cli/commands/install_command.go b/pkg/cmd/grafana-cli/commands/install_command.go index 8a2634dbcd9..f60c02b8072 100644 --- a/pkg/cmd/grafana-cli/commands/install_command.go +++ b/pkg/cmd/grafana-cli/commands/install_command.go @@ -230,6 +230,16 @@ func extractFiles(archiveFile string, pluginName string, dstDir string, allowSym } logger.Debugf("Extracting archive %q to %q...\n", archiveFile, dstDir) + existingInstallDir := filepath.Join(dstDir, pluginName) + if _, err := os.Stat(existingInstallDir); !os.IsNotExist(err) { + err = os.RemoveAll(existingInstallDir) + if err != nil { + return err + } + + logger.Infof("Removed existing installation of %s\n\n", pluginName) + } + r, err := zip.OpenReader(archiveFile) if err != nil { return err