windows: fix error reporting for uv_fs_ functions

This commit is contained in:
Igor Zinkovsky 2011-09-28 12:46:37 -07:00
parent e7a53aed48
commit 4fb120f649
3 changed files with 28 additions and 4 deletions

View File

@ -76,6 +76,8 @@
#define SET_UV_LAST_ERROR_FROM_REQ(req) \
if (req->flags & UV_FS_LAST_ERROR_SET) { \
uv__set_sys_error(req->loop, req->last_error); \
} else if (req->result == -1) { \
uv__set_error(req->loop, req->errorno, req->last_error); \
}
#define SET_REQ_LAST_ERROR(req, error) \
@ -85,7 +87,8 @@
#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = uv_translate_sys_error(_doserrno); \
req->last_error = _doserrno; \
req->errorno = uv_translate_sys_error(req->last_error); \
}
#define SET_REQ_RESULT_WIN32_ERROR(req, sys_errno) \
@ -576,11 +579,14 @@ void fs__symlink(uv_fs_t* req, const char* path, const char* new_path,
path,
flags & UV_FS_SYMLINK_DIR ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0) ? 0 : -1;
if (result == -1) {
SET_REQ_LAST_ERROR(req, GetLastError());
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}
} else {
result = -1;
errno = ENOSYS;
req->result = -1;
req->errorno = UV_ENOTSUP;
req->last_error = ERROR_SUCCESS;
return;
}
SET_REQ_RESULT(req, result);

View File

@ -1245,3 +1245,19 @@ TEST_IMPL(fs_futime) {
return 0;
}
TEST_IMPL(fs_stat_missing_path) {
uv_fs_t req;
int r;
loop = uv_default_loop();
r = uv_fs_stat(loop, &req, "non_existent_file", NULL);
ASSERT(r == -1);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req);
return 0;
}

View File

@ -91,6 +91,7 @@ TEST_DECLARE (fs_link)
TEST_DECLARE (fs_symlink)
TEST_DECLARE (fs_utime)
TEST_DECLARE (fs_futime)
TEST_DECLARE (fs_stat_missing_path)
TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
@ -216,6 +217,7 @@ TASK_LIST_START
TEST_ENTRY (fs_utime)
TEST_ENTRY (fs_futime)
TEST_ENTRY (fs_symlink)
TEST_ENTRY (fs_stat_missing_path)
TEST_ENTRY (fs_event_watch_dir)
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_current_dir)