Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: enable uv_fs_open to open directories

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Oct 12, 2011
1 parent 25a177a commit 2216d38c295ab728194d4933d506421495b73356
Showing with 49 additions and 1 deletion.
  1. +5 −0 src/win/fs.c
  2. +42 −0 test/test-fs.c
  3. +2 −1 test/test-list.h
@@ -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,
@@ -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);
@@ -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;
}
@@ -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)
@@ -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

0 comments on commit 2216d38

Please sign in to comment.
You can’t perform that action at this time.