From 656a0c42be3e4b240ad2aa02d489b5fa0554c695 Mon Sep 17 00:00:00 2001 From: Anusha Ragunathan Date: Wed, 16 Nov 2016 14:42:46 -0800 Subject: [PATCH] Cleanup after plugin install. During error cases, we dont cleanup correctly. This commit takes care of removing the plugin, if there are errors after the pull passed. It also shuts down the plugin, if there are errors after the plugin in the enable path. Signed-off-by: Anusha Ragunathan Upstream-commit: 4749582510fdda9189ecb582b131945fb1b1297b Component: cli --- components/cli/plugin_install.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/cli/plugin_install.go b/components/cli/plugin_install.go index d0a3d517fc..407f1cddf2 100644 --- a/components/cli/plugin_install.go +++ b/components/cli/plugin_install.go @@ -10,7 +10,7 @@ import ( ) // PluginInstall installs a plugin -func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) error { +func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (err error) { // FIXME(vdemeester) name is a ref, we might want to parse/validate it here. query := url.Values{} query.Set("name", name) @@ -27,6 +27,14 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types ensureReaderClosed(resp) return err } + + defer func() { + if err != nil { + delResp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil) + ensureReaderClosed(delResp) + } + }() + var privileges types.PluginPrivileges if err := json.NewDecoder(resp.body).Decode(&privileges); err != nil { ensureReaderClosed(resp) @@ -40,8 +48,6 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types return err } if !accept { - resp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil) - ensureReaderClosed(resp) return pluginPermissionDenied{name} } }