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.
@@ -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,11 +189,14 @@ 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<PosixFilePermission> perms = new HashSet<>();
+ final PosixFileAttributeView view =
+ Files.getFileAttributeView(outputFile, PosixFileAttributeView.class);
+ if (view != null) {
+ final Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
@@ -202,5 +206,6 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
perms.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(outputFile, perms);
}
+ }
}
