Plugins: Add executable flag to every file in bin/ after install

The PluginManager does not preserve permissions on install. This patch
sets the executable flag on every file in bin/ on plugin install.

Closes #7177
This commit is contained in:
Alexander Reelsen 2014-08-14 10:53:08 +02:00
parent 4d05d1d7b0
commit 6023a3a1a1
2 changed files with 18 additions and 1 deletions

View File

@ -43,6 +43,11 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -235,6 +240,16 @@ public class PluginManager {
if (!binFile.renameTo(toLocation)) { if (!binFile.renameTo(toLocation)) {
throw new IOException("Could not move ["+ binFile.getAbsolutePath() + "] to [" + toLocation.getAbsolutePath() + "]"); throw new IOException("Could not move ["+ binFile.getAbsolutePath() + "] to [" + toLocation.getAbsolutePath() + "]");
} }
// Make everything in bin/ executable
Files.walkFileTree(toLocation.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (attrs.isRegularFile()) {
file.toFile().setExecutable(true);
}
return FileVisitResult.CONTINUE;
}
});
debug("Installed " + name + " into " + toLocation.getAbsolutePath()); debug("Installed " + name + " into " + toLocation.getAbsolutePath());
potentialSitePlugin = false; potentialSitePlugin = false;
} }

View File

@ -116,7 +116,9 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
assertThat(plugins.length, is(1)); assertThat(plugins.length, is(1));
assertTrue(pluginBinDir.exists()); assertTrue(pluginBinDir.exists());
assertTrue(pluginConfigDir.exists()); assertTrue(pluginConfigDir.exists());
File toolFile = new File(pluginBinDir, "tool");
assertThat(toolFile.exists(), is(true));
assertThat(toolFile.canExecute(), is(true));
} finally { } finally {
// we need to clean up the copied dirs // we need to clean up the copied dirs
FileSystemUtils.deleteRecursively(pluginBinDir); FileSystemUtils.deleteRecursively(pluginBinDir);