提交 9ebf0f88 编写于 作者: A alanb

6866804: (file) Path calls checkPermission insteadof checkXXX (sol)

Reviewed-by: sherman
上级 acd702cf
...@@ -65,9 +65,6 @@ class UnixPath ...@@ -65,9 +65,6 @@ class UnixPath
// array of offsets of elements in path (created lazily) // array of offsets of elements in path (created lazily)
private volatile int[] offsets; private volatile int[] offsets;
// file permissions (created lazily)
private volatile FilePermission[] perms;
UnixPath(UnixFileSystem fs, byte[] path) { UnixPath(UnixFileSystem fs, byte[] path) {
this.fs = fs; this.fs = fs;
this.path = path; this.path = path;
...@@ -768,45 +765,23 @@ class UnixPath ...@@ -768,45 +765,23 @@ class UnixPath
} }
} }
// create file permissions used for read and write checks
private void checkReadOrWrite(boolean checkRead) {
SecurityManager sm = System.getSecurityManager();
if (sm == null)
return;
if (perms == null) {
synchronized (this) {
if (perms == null) {
FilePermission[] p = new FilePermission[2];
String pathForPermCheck = getPathForPermissionCheck();
p[0] = new FilePermission(pathForPermCheck,
SecurityConstants.FILE_READ_ACTION);
p[1] = new FilePermission(pathForPermCheck,
SecurityConstants.FILE_WRITE_ACTION);
perms = p;
}
}
}
if (checkRead) {
sm.checkPermission(perms[0]);
} else {
sm.checkPermission(perms[1]);
}
}
void checkRead() { void checkRead() {
checkReadOrWrite(true); SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkRead(getPathForPermissionCheck());
} }
void checkWrite() { void checkWrite() {
checkReadOrWrite(false); SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkWrite(getPathForPermissionCheck());
} }
void checkDelete() { void checkDelete() {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null)
// permission not cached
sm.checkDelete(getPathForPermissionCheck()); sm.checkDelete(getPathForPermissionCheck());
}
} }
@Override @Override
......
...@@ -46,6 +46,7 @@ class WindowsFileAttributeViews { ...@@ -46,6 +46,7 @@ class WindowsFileAttributeViews {
@Override @Override
public WindowsFileAttributes readAttributes() throws IOException { public WindowsFileAttributes readAttributes() throws IOException {
file.checkRead();
try { try {
return WindowsFileAttributes.get(file, followLinks); return WindowsFileAttributes.get(file, followLinks);
} catch (WindowsException x) { } catch (WindowsException x) {
......
此差异已折叠。
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 4313887 6838333 6866804 * @bug 4313887 6838333 6867101
* @summary Unit test for java.nio.file.Path for miscellenous methods not * @summary Unit test for java.nio.file.Path for miscellenous methods not
* covered by other tests * covered by other tests
* @library .. * @library ..
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册