From dd18517ab5b3738b4dc511e5d690fc24b55265e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 12 Feb 2025 15:54:06 +0100 Subject: [PATCH 1/2] Add test --- test/test-fs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test-fs.c b/test/test-fs.c index e2c05db3..6641beac 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -1717,6 +1717,18 @@ TEST_IMPL(fs_access) { ASSERT_EQ(1, access_cb_count); access_cb_count = 0; /* reset for the next test */ + /* Make the file read-only */ + r = uv_fs_fchmod(NULL, &req, file, 0400, NULL); + ASSERT_OK(r); + ASSERT_OK(req.result); + uv_fs_req_cleanup(&req); + + /* Check that the file is not writable */ + r = uv_fs_access(NULL, &req, "test_file", W_OK, NULL); + ASSERT_EQ(r, UV_EACCES); + ASSERT_EQ(req.result, UV_EACCES); + uv_fs_req_cleanup(&req); + /* Close file */ r = uv_fs_close(NULL, &req, file, NULL); ASSERT_OK(r); @@ -1740,6 +1752,8 @@ TEST_IMPL(fs_access) { uv_run(loop, UV_RUN_DEFAULT); /* Cleanup. */ + uv_fs_chmod(NULL, &req, "test_file", 0600, NULL); + uv_fs_req_cleanup(&req); unlink("test_file"); rmdir("test_dir"); From 31f365ddca99aafff130f144cf28c15c0ec24835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 12 Feb 2025 15:33:43 +0100 Subject: [PATCH 2/2] win: access should fail with EACCES, not EPERM See https://pubs.opengroup.org/onlinepubs/9799919799/functions/access.html --- src/win/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/fs.c b/src/win/fs.c index a85695b2..91fb6005 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -2118,7 +2118,7 @@ static void fs__access(uv_fs_t* req) { (attr & FILE_ATTRIBUTE_DIRECTORY)) { SET_REQ_RESULT(req, 0); } else { - SET_REQ_WIN32_ERROR(req, UV_EPERM); + SET_REQ_WIN32_ERROR(req, UV_EACCES); } }