From 79c0fa4ca5acb979c054cd78e99a92ecff0e5301 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 4 Dec 2019 12:48:40 +0100 Subject: [PATCH] CLI: Return error and aborts when plugin file extraction fails (#20849) Return error and aborts when plugin file extraction fails. If file is in use, a somewhat user-friendly message is returned. Fixes #20841 --- pkg/cmd/grafana-cli/commands/install_command.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/install_command.go b/pkg/cmd/grafana-cli/commands/install_command.go index 69659d12356..0a657091e7e 100644 --- a/pkg/cmd/grafana-cli/commands/install_command.go +++ b/pkg/cmd/grafana-cli/commands/install_command.go @@ -241,11 +241,9 @@ func extractFiles(archiveFile string, pluginName string, filePath string, allowS continue } } else { - err = extractFile(zf, newFile) if err != nil { - logger.Errorf("Failed to extract file: %v \n", err) - continue + return errutil.Wrap("Failed to extract file", err) } } } @@ -288,6 +286,12 @@ func extractFile(file *zip.File, filePath string) (err error) { if os.IsPermission(err) { return xerrors.Errorf(permissionsDeniedMessage, filePath) } + + unwrappedError := xerrors.Unwrap(err) + if unwrappedError != nil && strings.EqualFold(unwrappedError.Error(), "text file busy") { + return fmt.Errorf("file %s is in use. Please stop Grafana, install the plugin and restart Grafana", filePath) + } + return errutil.Wrap("Failed to open file", err) } defer func() {