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

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

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