8080629: (fs) Re-enable ability to fsync() on directories even though read()s on those directories may fail.
authorbpb
Tue, 19 May 2015 07:12:10 -0700
changeset 30656 daa60ed28ab1
parent 30655 d83f50188ca9
child 30657 e35c8942b5bb
8080629: (fs) Re-enable ability to fsync() on directories even though read()s on those directories may fail. Summary: Revert fix applied to resolve JDK-8066915. Reviewed-by: alanb
jdk/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java
jdk/test/java/nio/file/Files/SBC.java
--- a/jdk/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java	Tue May 19 16:04:14 2015 +0400
+++ b/jdk/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java	Tue May 19 07:12:10 2015 -0700
@@ -270,22 +270,6 @@
             throw x;
         }
 
-        // fail if the file is a directory
-        if (flags.read) {
-            UnixException exc = null;
-            try {
-                if (UnixFileAttributes.get(fd).isDirectory()) {
-                    exc = new UnixException(EISDIR);
-                }
-            } catch (UnixException x) {
-                exc = x;
-            }
-            if (exc != null) {
-                close(fd);
-                throw exc;
-            }
-        }
-
         // unlink file immediately if delete on close. The spec is clear that
         // an implementation cannot guarantee to unlink the correct file when
         // replaced by an attacker after it is opened.
--- a/jdk/test/java/nio/file/Files/SBC.java	Tue May 19 16:04:14 2015 +0400
+++ b/jdk/test/java/nio/file/Files/SBC.java	Tue May 19 07:12:10 2015 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 8066915
+ * @bug 4313887
  * @summary Unit test for java.nio.file.Files.newByteChannel
  * @library ..
  */
@@ -59,7 +59,6 @@
                 dosSharingOptionTests(dir);
 
             // misc. tests
-            directoryOpenTests(dir);
             badCombinations(dir);
             unsupportedOptions(dir);
             nullTests(dir);
@@ -279,21 +278,6 @@
         }
     }
 
-    // test opening a directory for read or write
-    static void directoryOpenTests(Path dir) throws Exception {
-        try (SeekableByteChannel sbc = Files.newByteChannel(dir, READ)) {
-            throw new RuntimeException("Opened directory for read");
-        } catch (IOException expected) { }
-
-        try (SeekableByteChannel sbc = Files.newByteChannel(dir, WRITE)) {
-            throw new RuntimeException("Opened directory for write");
-        } catch (IOException expected) { }
-
-        try (SeekableByteChannel sbc = Files.newByteChannel(dir, APPEND)) {
-            throw new RuntimeException("Opened directory for append ");
-        } catch (IOException expected) { }
-    }
-
     // Windows specific options for the use by applications that really want
     // to use legacy DOS sharing options
     static void dosSharingOptionTests(Path dir) throws Exception {