changeset 50994:09776f847bf4

8198405: JImageExtractTest.java & JImageListTest.java failed in Windows. Summary: Make a directory readonly using nio file attribute AclEntry Reviewed-by: jlaskey
author sdama
date Fri, 06 Jul 2018 00:40:12 +0530
parents 3924d4cf8b41
children 3c59afe1afc9
files test/jdk/ProblemList.txt test/jdk/tools/jimage/JImageExtractTest.java
diffstat 2 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/ProblemList.txt	Thu Jul 05 21:29:11 2018 +0300
+++ b/test/jdk/ProblemList.txt	Fri Jul 06 00:40:12 2018 +0530
@@ -820,9 +820,6 @@
 
 tools/pack200/CommandLineTests.java                             8059906 generic-all
 
-tools/jimage/JImageExtractTest.java                             8198405 windows-all
-tools/jimage/JImageListTest.java                                8198405 windows-all
-
 ############################################################################
 
 # jdk_jdi
--- a/test/jdk/tools/jimage/JImageExtractTest.java	Thu Jul 05 21:29:11 2018 +0300
+++ b/test/jdk/tools/jimage/JImageExtractTest.java	Fri Jul 06 00:40:12 2018 +0530
@@ -34,11 +34,10 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.attribute.FileAttribute;
-import java.nio.file.attribute.PosixFilePermission;
-import java.nio.file.attribute.PosixFilePermissions;
+import java.nio.file.attribute.*;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -145,15 +144,25 @@
     }
 
     public void testExtractToReadOnlyDir() throws IOException {
-        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r-xr--r--");
-        Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
-        String os = System.getProperty("os.name").toLowerCase();
-        if (os.indexOf("win") >= 0) {
-            Files.setAttribute(tmp, "dos:readonly", true);
-        } else {
-            Files.setPosixFilePermissions(tmp, perms);
+        Path filePath = Files.createTempDirectory(Paths.get("."), getClass().getName());
+        Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();
+        if (supportedAttr.contains("posix")) {
+            Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("r-xr--r--"));
+        } else if (supportedAttr.contains("acl")) {
+            System.out.println("Entered into acl block");
+            UserPrincipal fileOwner = Files.getOwner(filePath);
+            AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
+            AclEntry entry = AclEntry.newBuilder()
+                                     .setType(AclEntryType.DENY)
+                                     .setPrincipal(fileOwner)
+                                     .setPermissions(AclEntryPermission.WRITE_DATA)
+                                     .setFlags(AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT)
+                                     .build();
+            List<AclEntry> acl = view.getAcl();
+            acl.add(0, entry);
+            view.setAcl(acl);
         }
-        jimage("extract", "--dir", tmp.toString(), getImagePath())
+        jimage("extract", "--dir", filePath.toString(), getImagePath())
                 .assertFailure()
                 .assertShowsError();
     }