changeset 5263:226981134147

7168172: (fs) Files.isReadable slow on Windows Summary: Remove DACL checking for read access, also reviewed by zhong.j.yu@gmail.com Reviewed-by: alanb, ulfzibis
author khazra
date Mon, 27 Aug 2012 17:08:54 -0700
parents 589c21e1aa30
children f7ac6a1d5853
files src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java
diffstat 1 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java	Mon Aug 27 21:38:54 2012 +0400
+++ b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java	Mon Aug 27 17:08:54 2012 -0700
@@ -352,19 +352,34 @@
         }
     }
 
+    /**
+     * Checks if the given file(or directory) exists and is readable.
+     */
+    private void checkReadAccess(WindowsPath file) throws IOException {
+        try {
+            Set<OpenOption> opts = Collections.emptySet();
+            FileChannel fc = WindowsChannelFactory
+                .newFileChannel(file.getPathForWin32Calls(),
+                                file.getPathForPermissionCheck(),
+                                opts,
+                                0L);
+            fc.close();
+        } catch (WindowsException exc) {
+            // Windows errors are very inconsistent when the file is a directory
+            // (ERROR_PATH_NOT_FOUND returned for root directories for example)
+            // so we retry by attempting to open it as a directory.
+            try {
+                new WindowsDirectoryStream(file, null).close();
+            } catch (IOException ioe) {
+                // translate and throw original exception
+                exc.rethrowAsIOException(file);
+            }
+        }
+    }
+
     @Override
     public void checkAccess(Path obj, AccessMode... modes) throws IOException {
         WindowsPath file = WindowsPath.toWindowsPath(obj);
-        // if no access modes then simply file attributes
-        if (modes.length == 0) {
-            file.checkRead();
-            try {
-                WindowsFileAttributes.get(file, true);
-            } catch (WindowsException exc) {
-                exc.rethrowAsIOException(file);
-            }
-            return;
-        }
 
         boolean r = false;
         boolean w = false;
@@ -378,6 +393,13 @@
             }
         }
 
+        // special-case read access to avoid needing to determine effective
+        // access to file; default if modes not specified
+        if (!w && !x) {
+            checkReadAccess(file);
+            return;
+        }
+
         int mask = 0;
         if (r) {
             file.checkRead();