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

Commit

Permalink
windows: fix error reporting for uv_fs_ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Sep 28, 2011
1 parent e7a53ae commit 4fb120f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/win/fs.c
Expand Up @@ -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) \
Expand All @@ -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) \
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/test-fs.c
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4fb120f

Please sign in to comment.