提交 554f8842 编写于 作者: A alanb

4939819: File.canWrite() returns false for the "My Documents" directory (win)

Reviewed-by: iris
上级 ae942eac
...@@ -229,26 +229,29 @@ JNIEXPORT jboolean ...@@ -229,26 +229,29 @@ JNIEXPORT jboolean
JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this, JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this,
jobject file, jint access) jobject file, jint access)
{ {
jboolean rv = JNI_FALSE; DWORD attr;
int mode;
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
if (pathbuf == NULL) if (pathbuf == NULL)
return JNI_FALSE; return JNI_FALSE;
attr = GetFileAttributesW(pathbuf);
free(pathbuf);
if (attr == INVALID_FILE_ATTRIBUTES)
return JNI_FALSE;
switch (access) { switch (access) {
case java_io_FileSystem_ACCESS_READ: case java_io_FileSystem_ACCESS_READ:
case java_io_FileSystem_ACCESS_EXECUTE: case java_io_FileSystem_ACCESS_EXECUTE:
mode = 4; return JNI_TRUE;
break;
case java_io_FileSystem_ACCESS_WRITE: case java_io_FileSystem_ACCESS_WRITE:
mode = 2; /* Read-only attribute ignored on directories */
break; if ((attr & FILE_ATTRIBUTE_DIRECTORY) ||
default: assert(0); (attr & FILE_ATTRIBUTE_READONLY) == 0)
} return JNI_TRUE;
if (_waccess(pathbuf, mode) == 0) { else
rv = JNI_TRUE; return JNI_FALSE;
default:
assert(0);
return JNI_FALSE;
} }
free(pathbuf);
return rv;
} }
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
@bug 4091757 @bug 4091757 4939819
@summary Basic test for setReadOnly method @summary Basic test for setReadOnly method
*/ */
...@@ -59,8 +59,15 @@ public class SetReadOnly { ...@@ -59,8 +59,15 @@ public class SetReadOnly {
throw new Exception(f + ": Cannot create directory"); throw new Exception(f + ": Cannot create directory");
if (!f.setReadOnly()) if (!f.setReadOnly())
throw new Exception(f + ": Failed on directory"); throw new Exception(f + ": Failed on directory");
// The readonly attribute on Windows does not make a folder read-only
if (System.getProperty("os.name").startsWith("Windows")) {
if (!f.canWrite())
throw new Exception(f + ": Directory is not writeable");
} else {
if (f.canWrite()) if (f.canWrite())
throw new Exception(f + ": Directory is writeable"); throw new Exception(f + ": Directory is writeable");
}
if (!f.delete()) if (!f.delete())
throw new Exception(f + ": Cannot delete directory"); throw new Exception(f + ": Cannot delete directory");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册