Print message when removing plugin with config
When removing a plugin with a config directory, we preserve the config directory. This is because the workflow for upgrading a plugin involves removing and then installing the plugin again and losing the plugin config in this case would be terrible. This commit causes a message regarding this to be printed in case the user wants to manually delete these files.
This commit is contained in:
parent
ab86660c65
commit
75956604eb
|
@ -88,5 +88,12 @@ final class RemovePluginCommand extends SettingCommand {
|
|||
pluginPaths.add(tmpPluginDir);
|
||||
|
||||
IOUtils.rm(pluginPaths.toArray(new Path[pluginPaths.size()]));
|
||||
|
||||
// we preserve the config files in case the user is upgrading the plugin, but we print
|
||||
// a message so the user knows in case they want to remove manually
|
||||
final Path pluginConfigDir = env.configFile().resolve(pluginName);
|
||||
if (Files.exists(pluginConfigDir)) {
|
||||
terminal.println("-> Preserving plugin config files: " + pluginConfigDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
|
||||
package org.elasticsearch.plugins;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.cli.MockTerminal;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
|
@ -26,13 +34,8 @@ import java.nio.file.Path;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.cli.MockTerminal;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
|
||||
@LuceneTestCase.SuppressFileSystems("*")
|
||||
public class RemovePluginCommandTests extends ESTestCase {
|
||||
|
@ -109,4 +112,22 @@ public class RemovePluginCommandTests extends ESTestCase {
|
|||
assertRemoveCleaned(env);
|
||||
}
|
||||
|
||||
public void testConfigDirPreserved() throws Exception {
|
||||
Files.createDirectories(env.pluginsFile().resolve("fake"));
|
||||
final Path configDir = env.configFile().resolve("fake");
|
||||
Files.createDirectories(configDir);
|
||||
Files.createFile(configDir.resolve("fake.yml"));
|
||||
final MockTerminal terminal = removePlugin("fake", home);
|
||||
assertTrue(Files.exists(env.configFile().resolve("fake")));
|
||||
assertThat(terminal.getOutput(), containsString("-> Preserving plugin config files: " + configDir));
|
||||
assertRemoveCleaned(env);
|
||||
}
|
||||
|
||||
public void testNoConfigDirPreserved() throws Exception {
|
||||
Files.createDirectories(env.pluginsFile().resolve("fake"));
|
||||
final Path configDir = env.configFile().resolve("fake");
|
||||
final MockTerminal terminal = removePlugin("fake", home);
|
||||
assertThat(terminal.getOutput(), not(containsString("-> Preserving plugin config files: " + configDir)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue