Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
uv: apply floating patch 2f54947b
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Sep 23, 2014
1 parent c5f5d4c commit 7fd35e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions deps/uv/src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,15 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
dents = NULL;
n = scandir(req->path, &dents, uv__fs_readdir_filter, alphasort);

/* NOTE: We will use nbufs as an index field */
req->nbufs = 0;

if (n == 0)
goto out; /* osx still needs to deallocate some memory */
else if (n == -1)
return n;

/* NOTE: We will use nbufs as an index field */
req->ptr = dents;
req->nbufs = 0;

return n;

Expand All @@ -334,6 +335,8 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
}
errno = saved_errno;

req->ptr = NULL;

return n;
}

Expand Down
8 changes: 8 additions & 0 deletions deps/uv/test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,13 @@ static void readdir_cb(uv_fs_t* req) {


static void empty_readdir_cb(uv_fs_t* req) {
uv_dirent_t dent;

ASSERT(req == &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR);
ASSERT(req->result == 0);
ASSERT(req->ptr == NULL);
ASSERT(UV_EOF == uv_fs_readdir_next(req, &dent));
uv_fs_req_cleanup(req);
readdir_cb_count++;
}
Expand Down Expand Up @@ -1805,6 +1808,7 @@ TEST_IMPL(fs_stat_missing_path) {
TEST_IMPL(fs_readdir_empty_dir) {
const char* path;
uv_fs_t req;
uv_dirent_t dent;
int r;

path = "./empty_dir/";
Expand All @@ -1813,10 +1817,14 @@ TEST_IMPL(fs_readdir_empty_dir) {
uv_fs_mkdir(loop, &req, path, 0777, NULL);
uv_fs_req_cleanup(&req);

/* 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);
ASSERT(r == 0);
ASSERT(req.result == 0);
ASSERT(req.ptr == NULL);
ASSERT(UV_EOF == uv_fs_readdir_next(&req, &dent));
uv_fs_req_cleanup(&req);

r = uv_fs_readdir(loop, &readdir_req, path, 0, empty_readdir_cb);
Expand Down

0 comments on commit 7fd35e6

Please sign in to comment.