From 4fb120f6494677ebfab0028a2f7b0cfd7dca09c4 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Wed, 28 Sep 2011 12:46:37 -0700 Subject: [PATCH] windows: fix error reporting for uv_fs_ functions --- src/win/fs.c | 14 ++++++++++---- test/test-fs.c | 16 ++++++++++++++++ test/test-list.h | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/win/fs.c b/src/win/fs.c index b6a9a5a3..2969cfa0 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -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); diff --git a/test/test-fs.c b/test/test-fs.c index fbe0396b..910e938d 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -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; +} \ No newline at end of file diff --git a/test/test-list.h b/test/test-list.h index 1d243c48..dcc56076 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -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)