Răsfoiți Sursa

Removing plugin does not fail when plugin dir is read only

If you try to remove a plugin in read only dir, you get a successful result:

```
$ bin/plugin --remove marvel
-> Removing marvel
Removed marvel
```

But actually the plugin has not been removed.

When installing, if fails properly:

```
$ bin/plugin -i elasticsearch/marvel/latest
-> Installing elasticsearch/marvel/latest...

Failed to install elasticsearch/marvel/latest, reason: plugin directory /usr/local/elasticsearch/plugins is read only
```

This change throw an exception when we don't succeed removing the plugin.

Closes #6546.
David Pilato 11 ani în urmă
părinte
comite
f0ad096bc4
1 a modificat fișierele cu 12 adăugiri și 3 ștergeri
  1. 12 3
      src/main/java/org/elasticsearch/plugins/PluginManager.java

+ 12 - 3
src/main/java/org/elasticsearch/plugins/PluginManager.java

@@ -248,19 +248,28 @@ public class PluginManager {
         File pluginToDelete = pluginHandle.extractedDir(environment);
         File pluginToDelete = pluginHandle.extractedDir(environment);
         if (pluginToDelete.exists()) {
         if (pluginToDelete.exists()) {
             debug("Removing: " + pluginToDelete.getPath());
             debug("Removing: " + pluginToDelete.getPath());
-            FileSystemUtils.deleteRecursively(pluginToDelete, true);
+            if (!FileSystemUtils.deleteRecursively(pluginToDelete, true)) {
+                throw new IOException("Unable to remove " + pluginHandle.name + ". Check file permissions on " +
+                        pluginToDelete.toString());
+            }
             removed = true;
             removed = true;
         }
         }
         pluginToDelete = pluginHandle.distroFile(environment);
         pluginToDelete = pluginHandle.distroFile(environment);
         if (pluginToDelete.exists()) {
         if (pluginToDelete.exists()) {
             debug("Removing: " + pluginToDelete.getPath());
             debug("Removing: " + pluginToDelete.getPath());
-            pluginToDelete.delete();
+            if (!pluginToDelete.delete()) {
+                throw new IOException("Unable to remove " + pluginHandle.name + ". Check file permissions on " +
+                        pluginToDelete.toString());
+            }
             removed = true;
             removed = true;
         }
         }
         File binLocation = pluginHandle.binDir(environment);
         File binLocation = pluginHandle.binDir(environment);
         if (binLocation.exists()) {
         if (binLocation.exists()) {
             debug("Removing: " + binLocation.getPath());
             debug("Removing: " + binLocation.getPath());
-            FileSystemUtils.deleteRecursively(binLocation);
+            if (!FileSystemUtils.deleteRecursively(binLocation)) {
+                throw new IOException("Unable to remove " + pluginHandle.name + ". Check file permissions on " +
+                        binLocation.toString());
+            }
             removed = true;
             removed = true;
         }
         }
         if (removed) {
         if (removed) {