Skip to content

Commit

Permalink
Skip hidden files when spawning
Browse files Browse the repository at this point in the history
When spawning a native controller, for now we should skip hidden
directories in the plugin folder. Future versions of Elasticsearch will
not be lenient here.

Relates #23980
  • Loading branch information
jasontedor committed Apr 7, 2017
1 parent b253138 commit 1a136bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/src/main/java/org/elasticsearch/bootstrap/Spawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

package org.elasticsearch.bootstrap;

import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.plugins.Platforms;
import org.elasticsearch.plugins.PluginInfo;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -59,6 +62,8 @@ public void close() throws IOException {
* @throws IOException if an I/O error occurs reading the plugins or spawning a native process
*/
void spawnNativePluginControllers(final Environment environment) throws IOException {
final Logger logger = Loggers.getLogger(getClass(), environment.settings());

if (!spawned.compareAndSet(false, true)) {
throw new IllegalStateException("native controllers already spawned");
}
Expand All @@ -72,6 +77,12 @@ void spawnNativePluginControllers(final Environment environment) throws IOExcept
*/
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pluginsFile)) {
for (final Path plugin : stream) {
if (FileSystemUtils.isHidden(plugin)) {
logger.trace(
"skipping hidden path in plugin directory [{}]",
plugin.toAbsolutePath());
continue;
}
final PluginInfo info = PluginInfo.readFromProperties(plugin);
final Path spawnPath = Platforms.nativeControllerPath(plugin);
if (!Files.isRegularFile(spawnPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ public void testControllerSpawn() throws IOException, InterruptedException {
}
}

public void testSpawnerSkipsHiddenFiles() throws IOException {
assert Version.CURRENT.before(Version.fromString("5.5.0"))
: "remove support for skipping hidden files in 5.5.0";
final Path esHome = createTempDir().resolve("home");
final Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.toString());
final Settings settings = settingsBuilder.build();

final Environment environment = new Environment(settings);

final Path hidden = environment.pluginsFile().resolve(".hidden");
Files.createDirectories(hidden);

Spawner spawner = new Spawner();
spawner.spawnNativePluginControllers(environment);
}

public void testControllerSpawnWithIncorrectDescriptor() throws IOException {
// this plugin will have a controller daemon
Path esHome = createTempDir().resolve("esHome");
Expand Down

0 comments on commit 1a136bd

Please sign in to comment.