From 4ee7f3521f9a5a2375c9c997ee36a7c79b1c90bc Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 8 Oct 2013 15:50:42 +0200 Subject: [PATCH] plugin -remove deletes bin directory I tried to install a plugin directly from disk, but used the wrong arguments. Totally my fault for not RTFM properly. However, by following the instructions printed out by `bin/plugin`, I ended up deleting my $ES/bin directory. ``` $ pwd /tmp/elasticsearch-0.90.5 $ ls LICENSE.txt NOTICE.txt README.textile bin config lib $ bin/plugin --install file:///tmp/foo.zip -> Installing file:///tmp/foo.zip... Failed to install file:///tmp/foo.zip, reason: plugin directory /tmp/elasticsearch-0.90.5/plugins already exists. To update the plugin, uninstall it first using -remove file:///tmp/foo.zip command $ bin/plugin -remove file:///tmp/foo.zip -> Removing file:///tmp/foo.zip Removed file:///tmp/foo.zip $ ls LICENSE.txt NOTICE.txt README.textile config lib ``` I reproduced the problem in 0.90.5 and the latest master. Closes #3847. --- .../java/org/elasticsearch/plugins/PluginManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/elasticsearch/plugins/PluginManager.java b/src/main/java/org/elasticsearch/plugins/PluginManager.java index c1b302f98db..0cc13a1f28f 100644 --- a/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -19,6 +19,8 @@ package org.elasticsearch.plugins; +import com.google.common.base.Strings; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.http.client.HttpDownloadHelper; @@ -221,6 +223,10 @@ public class PluginManager { PluginHandle pluginHandle = PluginHandle.parse(name); boolean removed = false; + if (Strings.isNullOrEmpty(pluginHandle.name)) { + throw new ElasticSearchIllegalArgumentException("plugin name is incorrect"); + } + File pluginToDelete = pluginHandle.extractedDir(environment); if (pluginToDelete.exists()) { debug("Removing: " + pluginToDelete.getPath()); @@ -331,6 +337,7 @@ public class PluginManager { // Deprecated commands || command.equals("remove") || command.equals("-remove")) { pluginName = args[++c]; + action = ACTION.REMOVE; } else if (command.equals("-l") || command.equals("--list")) { action = ACTION.LIST; @@ -371,6 +378,9 @@ public class PluginManager { pluginManager.log("-> Removing " + pluginName + " "); pluginManager.removePlugin(pluginName); exitCode = EXIT_CODE_OK; + } catch (ElasticSearchIllegalArgumentException e) { + exitCode = EXIT_CODE_CMD_USAGE; + pluginManager.log("Failed to remove " + pluginName + ", reason: " + e.getMessage()); } catch (IOException e) { exitCode = EXIT_CODE_IO_ERROR; pluginManager.log("Failed to remove " + pluginName + ", reason: " + e.getMessage());