win: fix uv_fs_access on directories
For posterity, these are the rules for access on Windows (taken from CPython's implementation), Access is possible if: * Write access wasn't requested * The file isn't read-only * It's a directory (directories cannot be read-only on Windows) PR-URL: https://github.com/libuv/libuv/pull/316 Reviewed-By: Bert Belder <bertbelder@gmail.com>
This commit is contained in:
parent
cdc10a907a
commit
7dcc3e0cf0
17
src/win/fs.c
17
src/win/fs.c
@ -1310,14 +1310,21 @@ static void fs__access(uv_fs_t* req) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((req->flags & W_OK) &&
|
/*
|
||||||
((attr & FILE_ATTRIBUTE_READONLY) ||
|
* Access is possible if
|
||||||
(attr & FILE_ATTRIBUTE_DIRECTORY))) {
|
* - write access wasn't requested,
|
||||||
|
* - or the file isn't read-only,
|
||||||
|
* - or it's a directory.
|
||||||
|
* (Directories cannot be read-only on Windows.)
|
||||||
|
*/
|
||||||
|
if (!(req->flags & W_OK) ||
|
||||||
|
!(attr & FILE_ATTRIBUTE_READONLY) ||
|
||||||
|
(attr & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||||
|
SET_REQ_RESULT(req, 0);
|
||||||
|
} else {
|
||||||
SET_REQ_WIN32_ERROR(req, UV_EPERM);
|
SET_REQ_WIN32_ERROR(req, UV_EPERM);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_REQ_RESULT(req, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1156,6 +1156,7 @@ TEST_IMPL(fs_access) {
|
|||||||
|
|
||||||
/* Setup. */
|
/* Setup. */
|
||||||
unlink("test_file");
|
unlink("test_file");
|
||||||
|
rmdir("test_dir");
|
||||||
|
|
||||||
loop = uv_default_loop();
|
loop = uv_default_loop();
|
||||||
|
|
||||||
@ -1199,6 +1200,16 @@ TEST_IMPL(fs_access) {
|
|||||||
ASSERT(req.result == 0);
|
ASSERT(req.result == 0);
|
||||||
uv_fs_req_cleanup(&req);
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
|
/* Directory access */
|
||||||
|
r = uv_fs_mkdir(loop, &req, "test_dir", 0777, NULL);
|
||||||
|
ASSERT(r == 0);
|
||||||
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
|
r = uv_fs_access(loop, &req, "test_dir", W_OK, NULL);
|
||||||
|
ASSERT(r == 0);
|
||||||
|
ASSERT(req.result == 0);
|
||||||
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run the loop just to check we don't have make any extraneous uv_ref()
|
* Run the loop just to check we don't have make any extraneous uv_ref()
|
||||||
* calls. This should drop out immediately.
|
* calls. This should drop out immediately.
|
||||||
@ -1207,6 +1218,7 @@ TEST_IMPL(fs_access) {
|
|||||||
|
|
||||||
/* Cleanup. */
|
/* Cleanup. */
|
||||||
unlink("test_file");
|
unlink("test_file");
|
||||||
|
rmdir("test_dir");
|
||||||
|
|
||||||
MAKE_VALGRIND_HAPPY();
|
MAKE_VALGRIND_HAPPY();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user