提交 b1da5910 编写于 作者: K khazra

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
上级 834d39a5
...@@ -352,20 +352,35 @@ public class WindowsFileSystemProvider ...@@ -352,20 +352,35 @@ public class WindowsFileSystemProvider
} }
} }
@Override /**
public void checkAccess(Path obj, AccessMode... modes) throws IOException { * Checks if the given file(or directory) exists and is readable.
WindowsPath file = WindowsPath.toWindowsPath(obj); */
// if no access modes then simply file attributes private void checkReadAccess(WindowsPath file) throws IOException {
if (modes.length == 0) {
file.checkRead();
try { try {
WindowsFileAttributes.get(file, true); Set<OpenOption> opts = Collections.emptySet();
FileChannel fc = WindowsChannelFactory
.newFileChannel(file.getPathForWin32Calls(),
file.getPathForPermissionCheck(),
opts,
0L);
fc.close();
} catch (WindowsException exc) { } 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); exc.rethrowAsIOException(file);
} }
return; }
} }
@Override
public void checkAccess(Path obj, AccessMode... modes) throws IOException {
WindowsPath file = WindowsPath.toWindowsPath(obj);
boolean r = false; boolean r = false;
boolean w = false; boolean w = false;
boolean x = false; boolean x = false;
...@@ -378,6 +393,13 @@ public class WindowsFileSystemProvider ...@@ -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; int mask = 0;
if (r) { if (r) {
file.checkRead(); file.checkRead();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册