From bc36cd803b8be32f1b9a8041cc503c303ad3873a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 7 Apr 2017 06:19:56 -0400 Subject: [PATCH] Fix permissions handling on Windows spawner test This commit fixes the handling of POSIX permissions on Windows in the spawner tests. Since POSIX permissions do not exist there, we first have to check if we are on a filesystem that supports POSIX or not before attempting to set the permissions. --- .../bootstrap/SpawnerNoBootstrapTests.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/qa/no-bootstrap-tests/src/test/java/org/elasticsearch/bootstrap/SpawnerNoBootstrapTests.java b/qa/no-bootstrap-tests/src/test/java/org/elasticsearch/bootstrap/SpawnerNoBootstrapTests.java index f81bd3b2d47..8da6d8d3afe 100644 --- a/qa/no-bootstrap-tests/src/test/java/org/elasticsearch/bootstrap/SpawnerNoBootstrapTests.java +++ b/qa/no-bootstrap-tests/src/test/java/org/elasticsearch/bootstrap/SpawnerNoBootstrapTests.java @@ -33,6 +33,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFilePermission; import java.util.HashSet; import java.util.List; @@ -188,19 +189,23 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase { equalTo("plugin [test_plugin] does not have permission to fork native controller")); } - private void createControllerProgram(Path outputFile) throws IOException { - Path outputDir = outputFile.getParent(); + private void createControllerProgram(final Path outputFile) throws IOException { + final Path outputDir = outputFile.getParent(); Files.createDirectories(outputDir); Files.write(outputFile, CONTROLLER_SOURCE.getBytes(StandardCharsets.UTF_8)); - Set perms = new HashSet<>(); - perms.add(PosixFilePermission.OWNER_READ); - perms.add(PosixFilePermission.OWNER_WRITE); - perms.add(PosixFilePermission.OWNER_EXECUTE); - perms.add(PosixFilePermission.GROUP_READ); - perms.add(PosixFilePermission.GROUP_EXECUTE); - perms.add(PosixFilePermission.OTHERS_READ); - perms.add(PosixFilePermission.OTHERS_EXECUTE); - Files.setPosixFilePermissions(outputFile, perms); + final PosixFileAttributeView view = + Files.getFileAttributeView(outputFile, PosixFileAttributeView.class); + if (view != null) { + final Set perms = new HashSet<>(); + perms.add(PosixFilePermission.OWNER_READ); + perms.add(PosixFilePermission.OWNER_WRITE); + perms.add(PosixFilePermission.OWNER_EXECUTE); + perms.add(PosixFilePermission.GROUP_READ); + perms.add(PosixFilePermission.GROUP_EXECUTE); + perms.add(PosixFilePermission.OTHERS_READ); + perms.add(PosixFilePermission.OTHERS_EXECUTE); + Files.setPosixFilePermissions(outputFile, perms); + } } }