From b1da5910c0898030c8644e5c14453ac1fa14b3c4 Mon Sep 17 00:00:00 2001 From: khazra Date: Fri, 24 Aug 2012 11:48:51 -0700 Subject: [PATCH] 7168172: (fs) Files.isReadable slow on Windows Summary: Remove DACL checking for read access, also reviewed by Ulf.Zibis@CoSoCo.de, zhong.j.yu@gmail.com Reviewed-by: alanb --- .../sun/nio/fs/WindowsFileSystemProvider.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java index bff9e0a60..a0020e52a 100644 --- a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java @@ -352,19 +352,34 @@ public class WindowsFileSystemProvider } } - @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(); + /** + * Checks if the given file(or directory) exists and is readable. + */ + private void checkReadAccess(WindowsPath file) throws IOException { + try { + Set 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 { - WindowsFileAttributes.get(file, true); - } catch (WindowsException exc) { + new WindowsDirectoryStream(file, null).close(); + } catch (IOException ioe) { + // translate and throw original exception exc.rethrowAsIOException(file); } - return; } + } + + @Override + public void checkAccess(Path obj, AccessMode... modes) throws IOException { + WindowsPath file = WindowsPath.toWindowsPath(obj); boolean r = false; boolean w = false; @@ -378,6 +393,13 @@ public class WindowsFileSystemProvider } } + // 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(); -- GitLab