Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
windows: enable uv_fs_open to open directories
  • Loading branch information
Igor Zinkovsky committed Oct 12, 2011
1 parent 25a177a commit 2216d38
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/win/fs.c
Expand Up @@ -231,6 +231,11 @@ void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
goto end;
}

/* Figure out whether path is a file or a directory. */
if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) {
attributes |= FILE_FLAG_BACKUP_SEMANTICS;
}

file = CreateFileA(path,
access,
share,
Expand Down
42 changes: 42 additions & 0 deletions test/test-fs.c
Expand Up @@ -263,6 +263,19 @@ static void open_cb(uv_fs_t* req) {
}


static void open_cb_simple(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
if (req->result < 0) {
/* TODO get error with uv_last_error() */
fprintf(stderr, "async open error: %d\n", req->errorno);
ASSERT(0);
}
open_cb_count++;
ASSERT(req->path);
uv_fs_req_cleanup(req);
}


static void fsync_cb(uv_fs_t* req) {
int r;
ASSERT(req == &fsync_req);
Expand Down Expand Up @@ -1366,3 +1379,32 @@ TEST_IMPL(fs_readdir_file) {

return 0;
}


TEST_IMPL(fs_open_dir) {
const char* path;
uv_fs_t req;
int r, file;

path = ".";
loop = uv_default_loop();

r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL);
ASSERT(r != -1);
ASSERT(req.result != -1);
ASSERT(req.ptr == NULL);
file = r;
uv_fs_req_cleanup(&req);

r = uv_fs_close(loop, &req, file, NULL);
ASSERT(r == 0);

r = uv_fs_open(loop, &req, path, O_RDONLY, 0, open_cb_simple);
ASSERT(r == 0);

ASSERT(open_cb_count == 0);
uv_run(loop);
ASSERT(open_cb_count == 1);

return 0;
}
3 changes: 2 additions & 1 deletion test/test-list.h
Expand Up @@ -103,6 +103,7 @@ TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir)
TEST_DECLARE (threadpool_queue_work_simple)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
Expand Down Expand Up @@ -240,7 +241,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_readdir_empty_dir)
TEST_ENTRY (fs_readdir_file)

TEST_ENTRY (fs_open_dir)
TEST_ENTRY (threadpool_queue_work_simple)

#if 0
Expand Down

0 comments on commit 2216d38

Please sign in to comment.