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

Commit

Permalink
fix fs_file_noent on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Sep 9, 2011
1 parent 0d373eb commit cfa1423
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
6 changes: 0 additions & 6 deletions src/uv-common.h
Expand Up @@ -31,12 +31,6 @@

#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))

/* Used for the uv_fs_ functions */
#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = errno; \
}

struct uv_ares_task_s {
UV_HANDLE_FIELDS
Expand Down
1 change: 1 addition & 0 deletions src/win/error.c
Expand Up @@ -96,6 +96,7 @@ char* uv_strerror(uv_err_t err) {
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_SUCCESS: return UV_OK;
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
case ERROR_NOACCESS: return UV_EACCESS;
case WSAEACCES: return UV_EACCESS;
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;
Expand Down
30 changes: 21 additions & 9 deletions src/win/fs.c
Expand Up @@ -82,6 +82,17 @@
req->last_error = error; \
req->flags |= UV_FS_LAST_ERROR_SET;

#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = uv_translate_sys_error(_doserrno); \
}

#define SET_REQ_RESULT_WIN32_ERROR(req, sys_errno) \
req->result = -1; \
req->errorno = uv_translate_sys_error(sys_errno); \
SET_REQ_LAST_ERROR(req, sys_errno);


void uv_fs_init() {
_fmode = _O_BINARY;
Expand Down Expand Up @@ -227,8 +238,8 @@ void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
attributes,
NULL);
if (file == INVALID_HANDLE_VALUE) {
result = -1;
goto end;
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}
result = _open_osfhandle((intptr_t)file, flags);
end:
Expand Down Expand Up @@ -356,9 +367,8 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
free(path2);

if(dir == INVALID_HANDLE_VALUE) {
result = -1;
SET_REQ_LAST_ERROR(req, GetLastError());
goto done;
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}

buf = (char*)malloc(buf_size);
Expand Down Expand Up @@ -439,9 +449,10 @@ void fs__rename(uv_fs_t* req, const char* path, const char* new_path) {
void fs__fsync(uv_fs_t* req, uv_file file) {
int result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1;
if (result == -1) {
SET_REQ_LAST_ERROR(req, GetLastError());
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
SET_REQ_RESULT(req, result);
}
SET_REQ_RESULT(req, result);
}


Expand Down Expand Up @@ -560,9 +571,10 @@ void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) {
void fs__link(uv_fs_t* req, const char* path, const char* new_path) {
int result = CreateHardLinkA(new_path, path, NULL) ? 0 : -1;
if (result == -1) {
SET_REQ_LAST_ERROR(req, GetLastError());
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
SET_REQ_RESULT(req, result);
}
SET_REQ_RESULT(req, result);
}


Expand Down
2 changes: 1 addition & 1 deletion test/test-fs.c
Expand Up @@ -391,7 +391,7 @@ TEST_IMPL(fs_file_noent) {
loop = uv_default_loop();

r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
ASSERT(r == -1);
ASSERT(r == 0);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req);
Expand Down

0 comments on commit cfa1423

Please sign in to comment.