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
This commit is contained in:
Marcus Efraimsson 2019-12-04 12:48:40 +01:00 committed by GitHub
parent 02bbdca604
commit 79c0fa4ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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() {