test: make sure that reading a directory fails
Fixes: https://github.com/libuv/libuv/issues/2026 PR-URL: https://github.com/libuv/libuv/pull/2029 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
20f2351886
commit
1dfa88f35b
@ -3037,6 +3037,60 @@ TEST_IMPL(fs_write_alotof_bufs_with_offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST_IMPL(fs_read_dir) {
|
||||
int r;
|
||||
char buf[2];
|
||||
loop = uv_default_loop();
|
||||
|
||||
/* Setup */
|
||||
rmdir("test_dir");
|
||||
r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
ASSERT(mkdir_cb_count == 1);
|
||||
/* Setup Done Here */
|
||||
|
||||
/* Get a file descriptor for the directory */
|
||||
r = uv_fs_open(loop,
|
||||
&open_req1,
|
||||
"test_dir",
|
||||
UV_FS_O_RDONLY | UV_FS_O_DIRECTORY,
|
||||
S_IWUSR | S_IRUSR,
|
||||
NULL);
|
||||
ASSERT(r >= 0);
|
||||
uv_fs_req_cleanup(&open_req1);
|
||||
|
||||
/* Try to read data from the directory */
|
||||
iov = uv_buf_init(buf, sizeof(buf));
|
||||
r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, 0, NULL);
|
||||
#if defined(__FreeBSD__) || \
|
||||
defined(__OpenBSD__) || \
|
||||
defined(__NetBSD__) || \
|
||||
defined(__DragonFly__) || \
|
||||
defined(_AIX) || \
|
||||
defined(__sun) || \
|
||||
defined(__MVS__)
|
||||
/*
|
||||
* As of now, these operating systems support reading from a directory,
|
||||
* that too depends on the filesystem this temporary test directory is
|
||||
* created on. That is why this assertion is a bit lenient.
|
||||
*/
|
||||
ASSERT((r >= 0) || (r == UV_EISDIR));
|
||||
#else
|
||||
ASSERT(r == UV_EISDIR);
|
||||
#endif
|
||||
uv_fs_req_cleanup(&read_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
/* Cleanup */
|
||||
rmdir("test_dir");
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
||||
@ -346,6 +346,7 @@ TEST_DECLARE (fs_partial_read)
|
||||
TEST_DECLARE (fs_partial_write)
|
||||
TEST_DECLARE (fs_file_pos_after_op_with_offset)
|
||||
TEST_DECLARE (fs_null_req)
|
||||
TEST_DECLARE (fs_read_dir)
|
||||
#ifdef _WIN32
|
||||
TEST_DECLARE (fs_exclusive_sharing_mode)
|
||||
TEST_DECLARE (fs_open_readonly_acl)
|
||||
@ -897,6 +898,7 @@ TASK_LIST_START
|
||||
TEST_ENTRY (fs_read_write_null_arguments)
|
||||
TEST_ENTRY (fs_file_pos_after_op_with_offset)
|
||||
TEST_ENTRY (fs_null_req)
|
||||
TEST_ENTRY (fs_read_dir)
|
||||
#ifdef _WIN32
|
||||
TEST_ENTRY (fs_exclusive_sharing_mode)
|
||||
TEST_ENTRY (fs_open_readonly_acl)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user