diff --git a/docs/src/fs.rst b/docs/src/fs.rst index d2db4081..c3817f2a 100644 --- a/docs/src/fs.rst +++ b/docs/src/fs.rst @@ -74,7 +74,7 @@ Data types UV_FS_MKDIR, UV_FS_MKDTEMP, UV_FS_RENAME, - UV_FS_READDIR, + UV_FS_SCANDIR, UV_FS_LINK, UV_FS_SYMLINK, UV_FS_READLINK, @@ -85,7 +85,7 @@ Data types .. c:type:: uv_dirent_t Cross platform (reduced) equivalent of ``struct dirent``. - Used in :c:func:`uv_fs_readdir_next`. + Used in :c:func:`uv_fs_scandir_next`. :: @@ -183,11 +183,11 @@ API Equivalent to ``rmdir(2)``. -.. c:function:: int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) -.. c:function:: int uv_fs_readdir_next(uv_fs_t* req, uv_dirent_t* ent) +.. c:function:: int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) +.. c:function:: int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) - Equivalent to ``readdir(2)``, with a slightly different API. Once the callback - for the request is called, the user can use :c:func:`uv_fs_readdir_next` to + Equivalent to ``scandir(3)``, with a slightly different API. Once the callback + for the request is called, the user can use :c:func:`uv_fs_scandir_next` to get `ent` populated with the next directory entry data. When there are no more entries ``UV_EOF`` will be returned. diff --git a/include/uv.h b/include/uv.h index 9ee9e9c4..42c6100a 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1031,7 +1031,7 @@ typedef enum { UV_FS_MKDIR, UV_FS_MKDTEMP, UV_FS_RENAME, - UV_FS_READDIR, + UV_FS_SCANDIR, UV_FS_LINK, UV_FS_SYMLINK, UV_FS_READLINK, @@ -1094,12 +1094,12 @@ UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb); -UV_EXTERN int uv_fs_readdir(uv_loop_t* loop, +UV_EXTERN int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb); -UV_EXTERN int uv_fs_readdir_next(uv_fs_t* req, +UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent); UV_EXTERN int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, diff --git a/src/unix/fs.c b/src/unix/fs.c index 9bb7baf7..cb8741b0 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -295,22 +295,21 @@ done: #if defined(__OpenBSD__) || (defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_8)) -static int uv__fs_readdir_filter(uv__dirent_t* dent) { +static int uv__fs_scandir_filter(uv__dirent_t* dent) { #else -static int uv__fs_readdir_filter(const uv__dirent_t* dent) { +static int uv__fs_scandir_filter(const uv__dirent_t* dent) { #endif return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0; } -/* This should have been called uv__fs_scandir(). */ -static ssize_t uv__fs_readdir(uv_fs_t* req) { +static ssize_t uv__fs_scandir(uv_fs_t* req) { uv__dirent_t **dents; int saved_errno; int n; dents = NULL; - n = scandir(req->path, &dents, uv__fs_readdir_filter, alphasort); + n = scandir(req->path, &dents, uv__fs_scandir_filter, alphasort); /* NOTE: We will use nbufs as an index field */ req->nbufs = 0; @@ -779,7 +778,7 @@ static void uv__fs_work(struct uv__work* w) { X(MKDIR, mkdir(req->path, req->mode)); X(MKDTEMP, uv__fs_mkdtemp(req)); X(READ, uv__fs_read(req)); - X(READDIR, uv__fs_readdir(req)); + X(SCANDIR, uv__fs_scandir(req)); X(READLINK, uv__fs_readlink(req)); X(RENAME, rename(req->path, req->new_path)); X(RMDIR, rmdir(req->path)); @@ -1040,12 +1039,12 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, } -int uv_fs_readdir(uv_loop_t* loop, +int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { - INIT(READDIR); + INIT(SCANDIR); PATH; req->flags = flags; POST; @@ -1167,8 +1166,8 @@ void uv_fs_req_cleanup(uv_fs_t* req) { req->path = NULL; req->new_path = NULL; - if (req->fs_type == UV_FS_READDIR && req->ptr != NULL) - uv__fs_readdir_cleanup(req); + if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL) + uv__fs_scandir_cleanup(req); if (req->ptr != &req->statbuf) free(req->ptr); diff --git a/src/uv-common.c b/src/uv-common.c index 13e732dd..97727baa 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -437,7 +437,7 @@ int uv_fs_event_getpath(uv_fs_event_t* handle, char* buf, size_t* len) { } -void uv__fs_readdir_cleanup(uv_fs_t* req) { +void uv__fs_scandir_cleanup(uv_fs_t* req) { uv__dirent_t** dents; dents = req->ptr; @@ -448,7 +448,7 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) { } -int uv_fs_readdir_next(uv_fs_t* req, uv_dirent_t* ent) { +int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) { uv__dirent_t** dents; uv__dirent_t* dent; diff --git a/src/uv-common.h b/src/uv-common.h index c9bad2f1..e06606c1 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -109,7 +109,7 @@ size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs); int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value); -void uv__fs_readdir_cleanup(uv_fs_t* req); +void uv__fs_scandir_cleanup(uv_fs_t* req); #define uv__has_active_reqs(loop) \ (QUEUE_EMPTY(&(loop)->active_reqs) == 0) diff --git a/src/win/fs.c b/src/win/fs.c index d3801460..4c319db6 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -783,7 +783,7 @@ void fs__mkdtemp(uv_fs_t* req) { } -void fs__readdir(uv_fs_t* req) { +void fs__scandir(uv_fs_t* req) { WCHAR* pathw = req->pathw; size_t len = wcslen(pathw); int result; @@ -1604,7 +1604,7 @@ static void uv__fs_work(struct uv__work* w) { XX(MKDIR, mkdir) XX(MKDTEMP, mkdtemp) XX(RENAME, rename) - XX(READDIR, readdir) + XX(SCANDIR, scandir) XX(LINK, link) XX(SYMLINK, symlink) XX(READLINK, readlink) @@ -1839,11 +1839,11 @@ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, +int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { int err; - uv_fs_req_init(loop, req, UV_FS_READDIR, cb); + uv_fs_req_init(loop, req, UV_FS_SCANDIR, cb); err = fs__capture_path(loop, req, path, NULL, cb != NULL); if (err) { @@ -1856,7 +1856,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, QUEUE_FS_TP_JOB(loop, req); return 0; } else { - fs__readdir(req); + fs__scandir(req); return req->result; } } diff --git a/test/test-fs.c b/test/test-fs.c index a514801b..db07ed2f 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -67,7 +67,7 @@ static int unlink_cb_count; static int mkdir_cb_count; static int mkdtemp_cb_count; static int rmdir_cb_count; -static int readdir_cb_count; +static int scandir_cb_count; static int stat_cb_count; static int rename_cb_count; static int fsync_cb_count; @@ -97,7 +97,7 @@ static uv_fs_t mkdir_req; static uv_fs_t mkdtemp_req1; static uv_fs_t mkdtemp_req2; static uv_fs_t rmdir_req; -static uv_fs_t readdir_req; +static uv_fs_t scandir_req; static uv_fs_t stat_req; static uv_fs_t rename_req; static uv_fs_t fsync_req; @@ -416,18 +416,18 @@ static void rmdir_cb(uv_fs_t* req) { } -static void readdir_cb(uv_fs_t* req) { +static void scandir_cb(uv_fs_t* req) { uv_dirent_t dent; - ASSERT(req == &readdir_req); - ASSERT(req->fs_type == UV_FS_READDIR); + ASSERT(req == &scandir_req); + ASSERT(req->fs_type == UV_FS_SCANDIR); ASSERT(req->result == 2); ASSERT(req->ptr); - while (UV_EOF != uv_fs_readdir_next(req, &dent)) { + while (UV_EOF != uv_fs_scandir_next(req, &dent)) { ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0); ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); } - readdir_cb_count++; + scandir_cb_count++; ASSERT(req->path); ASSERT(memcmp(req->path, "test_dir\0", 9) == 0); uv_fs_req_cleanup(req); @@ -435,26 +435,26 @@ static void readdir_cb(uv_fs_t* req) { } -static void empty_readdir_cb(uv_fs_t* req) { +static void empty_scandir_cb(uv_fs_t* req) { uv_dirent_t dent; - ASSERT(req == &readdir_req); - ASSERT(req->fs_type == UV_FS_READDIR); + ASSERT(req == &scandir_req); + ASSERT(req->fs_type == UV_FS_SCANDIR); ASSERT(req->result == 0); ASSERT(req->ptr == NULL); - ASSERT(UV_EOF == uv_fs_readdir_next(req, &dent)); + ASSERT(UV_EOF == uv_fs_scandir_next(req, &dent)); uv_fs_req_cleanup(req); - readdir_cb_count++; + scandir_cb_count++; } -static void file_readdir_cb(uv_fs_t* req) { - ASSERT(req == &readdir_req); - ASSERT(req->fs_type == UV_FS_READDIR); +static void file_scandir_cb(uv_fs_t* req) { + ASSERT(req == &scandir_req); + ASSERT(req->fs_type == UV_FS_SCANDIR); ASSERT(req->result == UV_ENOTDIR); ASSERT(req->ptr == NULL); uv_fs_req_cleanup(req); - readdir_cb_count++; + scandir_cb_count++; } @@ -841,23 +841,23 @@ TEST_IMPL(fs_async_dir) { ASSERT(r == 0); uv_fs_req_cleanup(&close_req); - r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, readdir_cb); + r = uv_fs_scandir(loop, &scandir_req, "test_dir", 0, scandir_cb); ASSERT(r == 0); uv_run(loop, UV_RUN_DEFAULT); - ASSERT(readdir_cb_count == 1); + ASSERT(scandir_cb_count == 1); - /* sync uv_fs_readdir */ - r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL); + /* sync uv_fs_scandir */ + r = uv_fs_scandir(loop, &scandir_req, "test_dir", 0, NULL); ASSERT(r == 2); - ASSERT(readdir_req.result == 2); - ASSERT(readdir_req.ptr); - while (UV_EOF != uv_fs_readdir_next(&readdir_req, &dent)) { + ASSERT(scandir_req.result == 2); + ASSERT(scandir_req.ptr); + while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) { ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0); ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); } - uv_fs_req_cleanup(&readdir_req); - ASSERT(!readdir_req.ptr); + uv_fs_req_cleanup(&scandir_req); + ASSERT(!scandir_req.ptr); r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb); ASSERT(r == 0); @@ -1604,36 +1604,36 @@ TEST_IMPL(fs_symlink_dir) { ASSERT(r == 0); uv_fs_req_cleanup(&close_req); - r = uv_fs_readdir(loop, &readdir_req, "test_dir_symlink", 0, NULL); + r = uv_fs_scandir(loop, &scandir_req, "test_dir_symlink", 0, NULL); ASSERT(r == 2); - ASSERT(readdir_req.result == 2); - ASSERT(readdir_req.ptr); - while (UV_EOF != uv_fs_readdir_next(&readdir_req, &dent)) { + ASSERT(scandir_req.result == 2); + ASSERT(scandir_req.ptr); + while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) { ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0); ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); } - uv_fs_req_cleanup(&readdir_req); - ASSERT(!readdir_req.ptr); + uv_fs_req_cleanup(&scandir_req); + ASSERT(!scandir_req.ptr); /* unlink will remove the directory symlink */ r = uv_fs_unlink(loop, &req, "test_dir_symlink", NULL); ASSERT(r == 0); uv_fs_req_cleanup(&req); - r = uv_fs_readdir(loop, &readdir_req, "test_dir_symlink", 0, NULL); + r = uv_fs_scandir(loop, &scandir_req, "test_dir_symlink", 0, NULL); ASSERT(r == UV_ENOENT); - uv_fs_req_cleanup(&readdir_req); + uv_fs_req_cleanup(&scandir_req); - r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL); + r = uv_fs_scandir(loop, &scandir_req, "test_dir", 0, NULL); ASSERT(r == 2); - ASSERT(readdir_req.result == 2); - ASSERT(readdir_req.ptr); - while (UV_EOF != uv_fs_readdir_next(&readdir_req, &dent)) { + ASSERT(scandir_req.result == 2); + ASSERT(scandir_req.ptr); + while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) { ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0); ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); } - uv_fs_req_cleanup(&readdir_req); - ASSERT(!readdir_req.ptr); + uv_fs_req_cleanup(&scandir_req); + ASSERT(!scandir_req.ptr); /* clean-up */ unlink("test_dir/file1"); @@ -1805,7 +1805,7 @@ TEST_IMPL(fs_stat_missing_path) { } -TEST_IMPL(fs_readdir_empty_dir) { +TEST_IMPL(fs_scandir_empty_dir) { const char* path; uv_fs_t req; uv_dirent_t dent; @@ -1820,19 +1820,19 @@ TEST_IMPL(fs_readdir_empty_dir) { /* Fill the req to ensure that required fields are cleaned up */ memset(&req, 0xdb, sizeof(req)); - r = uv_fs_readdir(loop, &req, path, 0, NULL); + r = uv_fs_scandir(loop, &req, path, 0, NULL); ASSERT(r == 0); ASSERT(req.result == 0); ASSERT(req.ptr == NULL); - ASSERT(UV_EOF == uv_fs_readdir_next(&req, &dent)); + ASSERT(UV_EOF == uv_fs_scandir_next(&req, &dent)); uv_fs_req_cleanup(&req); - r = uv_fs_readdir(loop, &readdir_req, path, 0, empty_readdir_cb); + r = uv_fs_scandir(loop, &scandir_req, path, 0, empty_scandir_cb); ASSERT(r == 0); - ASSERT(readdir_cb_count == 0); + ASSERT(scandir_cb_count == 0); uv_run(loop, UV_RUN_DEFAULT); - ASSERT(readdir_cb_count == 1); + ASSERT(scandir_cb_count == 1); uv_fs_rmdir(loop, &req, path, NULL); uv_fs_req_cleanup(&req); @@ -1842,23 +1842,23 @@ TEST_IMPL(fs_readdir_empty_dir) { } -TEST_IMPL(fs_readdir_file) { +TEST_IMPL(fs_scandir_file) { const char* path; int r; path = "test/fixtures/empty_file"; loop = uv_default_loop(); - r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL); + r = uv_fs_scandir(loop, &scandir_req, path, 0, NULL); ASSERT(r == UV_ENOTDIR); - uv_fs_req_cleanup(&readdir_req); + uv_fs_req_cleanup(&scandir_req); - r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb); + r = uv_fs_scandir(loop, &scandir_req, path, 0, file_scandir_cb); ASSERT(r == 0); - ASSERT(readdir_cb_count == 0); + ASSERT(scandir_cb_count == 0); uv_run(loop, UV_RUN_DEFAULT); - ASSERT(readdir_cb_count == 1); + ASSERT(scandir_cb_count == 1); MAKE_VALGRIND_HAPPY(); return 0; diff --git a/test/test-list.h b/test/test-list.h index 9cb65c39..90c0442b 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -241,8 +241,8 @@ TEST_DECLARE (fs_event_close_in_callback) TEST_DECLARE (fs_event_start_and_close) TEST_DECLARE (fs_event_error_reporting) TEST_DECLARE (fs_event_getpath) -TEST_DECLARE (fs_readdir_empty_dir) -TEST_DECLARE (fs_readdir_file) +TEST_DECLARE (fs_scandir_empty_dir) +TEST_DECLARE (fs_scandir_file) TEST_DECLARE (fs_open_dir) TEST_DECLARE (fs_rename_to_existing_file) TEST_DECLARE (threadpool_queue_work_simple) @@ -612,8 +612,8 @@ TASK_LIST_START TEST_ENTRY (fs_event_start_and_close) TEST_ENTRY (fs_event_error_reporting) TEST_ENTRY (fs_event_getpath) - TEST_ENTRY (fs_readdir_empty_dir) - TEST_ENTRY (fs_readdir_file) + TEST_ENTRY (fs_scandir_empty_dir) + TEST_ENTRY (fs_scandir_file) TEST_ENTRY (fs_open_dir) TEST_ENTRY (fs_rename_to_existing_file) TEST_ENTRY (threadpool_queue_work_simple) diff --git a/test/test-threadpool-cancel.c b/test/test-threadpool-cancel.c index d852e488..f999cba8 100644 --- a/test/test-threadpool-cancel.c +++ b/test/test-threadpool-cancel.c @@ -301,7 +301,7 @@ TEST_IMPL(threadpool_cancel_fs) { ASSERT(0 == uv_fs_mkdir(loop, reqs + n++, "/", 0, fs_cb)); ASSERT(0 == uv_fs_open(loop, reqs + n++, "/", 0, 0, fs_cb)); ASSERT(0 == uv_fs_read(loop, reqs + n++, 0, NULL, 0, 0, fs_cb)); - ASSERT(0 == uv_fs_readdir(loop, reqs + n++, "/", 0, fs_cb)); + ASSERT(0 == uv_fs_scandir(loop, reqs + n++, "/", 0, fs_cb)); ASSERT(0 == uv_fs_readlink(loop, reqs + n++, "/", fs_cb)); ASSERT(0 == uv_fs_rename(loop, reqs + n++, "/", "/", fs_cb)); ASSERT(0 == uv_fs_mkdir(loop, reqs + n++, "/", 0, fs_cb));