|
|
@ -38,7 +38,6 @@ |
|
|
|
#define UV_FS_FREE_ARG1 0x0004 |
|
|
|
#define UV_FS_FREE_PTR 0x0008 |
|
|
|
#define UV_FS_CLEANEDUP 0x0010 |
|
|
|
#define UV_FS_LAST_ERROR_SET 0x0020 |
|
|
|
|
|
|
|
|
|
|
|
#define UTF8_TO_UTF16(s, t) \ |
|
|
@ -88,33 +87,30 @@ |
|
|
|
uv_ref((loop)); |
|
|
|
|
|
|
|
#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, (uv_err_code)req->errorno, req->last_error); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define SET_REQ_LAST_ERROR(req, error) \ |
|
|
|
req->last_error = error; \ |
|
|
|
req->flags |= UV_FS_LAST_ERROR_SET; |
|
|
|
uv__set_error(req->loop, req->errorno, req->sys_errno_); |
|
|
|
|
|
|
|
#define SET_REQ_RESULT(req, result_value) \ |
|
|
|
req->result = (result_value); \ |
|
|
|
if (req->result == -1) { \ |
|
|
|
req->last_error = _doserrno; \ |
|
|
|
req->errorno = uv_translate_sys_error(req->last_error); \ |
|
|
|
req->sys_errno_ = _doserrno; \ |
|
|
|
req->errorno = uv_translate_sys_error(req->sys_errno_); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define SET_REQ_RESULT_WIN32_ERROR(req, sys_errno) \ |
|
|
|
#define SET_REQ_WIN32_ERROR(req, sys_errno) \ |
|
|
|
req->result = -1; \ |
|
|
|
req->sys_errno_ = (sys_errno); \ |
|
|
|
req->errorno = uv_translate_sys_error(req->sys_errno_); |
|
|
|
|
|
|
|
#define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \ |
|
|
|
req->result = -1; \ |
|
|
|
req->errorno = uv_translate_sys_error(sys_errno); \ |
|
|
|
SET_REQ_LAST_ERROR(req, sys_errno); |
|
|
|
req->sys_errno_ = (sys_errno); \ |
|
|
|
req->errorno = (uv_errno); |
|
|
|
|
|
|
|
#define VERIFY_UV_FILE(file, req) \ |
|
|
|
if (file == -1) { \ |
|
|
|
req->result = -1; \ |
|
|
|
req->errorno = UV_EBADF; \ |
|
|
|
req->last_error = ERROR_SUCCESS; \ |
|
|
|
req->sys_errno_ = ERROR_SUCCESS; \ |
|
|
|
return; \ |
|
|
|
} |
|
|
|
|
|
|
@ -137,7 +133,7 @@ static void uv_fs_req_init_async(uv_loop_t* loop, uv_fs_t* req, |
|
|
|
req->path = path ? strdup(path) : NULL; |
|
|
|
req->pathw = (wchar_t*)pathw; |
|
|
|
req->errorno = 0; |
|
|
|
req->last_error = 0; |
|
|
|
req->sys_errno_ = 0; |
|
|
|
memset(&req->overlapped, 0, sizeof(req->overlapped)); |
|
|
|
} |
|
|
|
|
|
|
@ -266,7 +262,15 @@ void fs__open(uv_fs_t* req, const wchar_t* path, int flags, int mode) { |
|
|
|
attributes, |
|
|
|
NULL); |
|
|
|
if (file == INVALID_HANDLE_VALUE) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
DWORD error = GetLastError(); |
|
|
|
if (error == ERROR_FILE_EXISTS && (flags & _O_CREAT) && |
|
|
|
!(flags & _O_EXCL)) { |
|
|
|
/* Special case: when ERROR_FILE_EXISTS happens and O_CREAT was */ |
|
|
|
/* specified, it means the path referred to a directory. */ |
|
|
|
SET_REQ_UV_ERROR(req, UV_EISDIR, error); |
|
|
|
} else { |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
result = _open_osfhandle((intptr_t)file, flags); |
|
|
@ -300,7 +304,7 @@ void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, |
|
|
|
} |
|
|
|
|
|
|
|
if (length > INT_MAX) { |
|
|
|
SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER); |
|
|
|
SET_REQ_WIN32_ERROR(req, ERROR_INSUFFICIENT_BUFFER); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -319,7 +323,7 @@ void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, |
|
|
|
if (ReadFile(handle, buf, length, &bytes, overlapped_ptr)) { |
|
|
|
SET_REQ_RESULT(req, bytes); |
|
|
|
} else { |
|
|
|
SET_REQ_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -340,7 +344,7 @@ void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length, |
|
|
|
} |
|
|
|
|
|
|
|
if (length > INT_MAX) { |
|
|
|
SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER); |
|
|
|
SET_REQ_WIN32_ERROR(req, ERROR_INSUFFICIENT_BUFFER); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -359,7 +363,7 @@ void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length, |
|
|
|
if (WriteFile(handle, buf, length, &bytes, overlapped_ptr)) { |
|
|
|
SET_REQ_RESULT(req, bytes); |
|
|
|
} else { |
|
|
|
SET_REQ_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -398,7 +402,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { |
|
|
|
if (!(GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY)) { |
|
|
|
req->result = -1; |
|
|
|
req->errorno = UV_ENOTDIR; |
|
|
|
req->last_error = ERROR_SUCCESS; |
|
|
|
req->sys_errno_ = ERROR_SUCCESS; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -416,7 +420,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { |
|
|
|
free(path2); |
|
|
|
|
|
|
|
if(dir == INVALID_HANDLE_VALUE) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -460,7 +464,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { |
|
|
|
/* Convert result to UTF8. */ |
|
|
|
size = uv_utf16_to_utf8(buf, buf_char_len, NULL, 0); |
|
|
|
if (!size) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -474,7 +478,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { |
|
|
|
free(buf); |
|
|
|
free(req->ptr); |
|
|
|
req->ptr = NULL; |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
free(buf); |
|
|
@ -491,7 +495,6 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { |
|
|
|
|
|
|
|
static void fs__stat(uv_fs_t* req, const wchar_t* path) { |
|
|
|
HANDLE handle; |
|
|
|
int result; |
|
|
|
BY_HANDLE_FILE_INFORMATION info; |
|
|
|
|
|
|
|
req->ptr = NULL; |
|
|
@ -504,12 +507,12 @@ static void fs__stat(uv_fs_t* req, const wchar_t* path) { |
|
|
|
FILE_FLAG_BACKUP_SEMANTICS, |
|
|
|
NULL); |
|
|
|
if (handle == INVALID_HANDLE_VALUE) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!GetFileInformationByHandle(handle, &info)) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
CloseHandle(handle); |
|
|
|
return; |
|
|
|
} |
|
|
@ -565,7 +568,7 @@ void fs__fstat(uv_fs_t* req, uv_file file) { |
|
|
|
|
|
|
|
void fs__rename(uv_fs_t* req, const wchar_t* path, const wchar_t* new_path) { |
|
|
|
if (!MoveFileExW(path, new_path, MOVEFILE_REPLACE_EXISTING)) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -580,7 +583,7 @@ void fs__fsync(uv_fs_t* req, uv_file file) { |
|
|
|
|
|
|
|
result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1; |
|
|
|
if (result == -1) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
} else { |
|
|
|
SET_REQ_RESULT(req, result); |
|
|
|
} |
|
|
@ -711,7 +714,7 @@ void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) { |
|
|
|
void fs__link(uv_fs_t* req, const wchar_t* path, const wchar_t* new_path) { |
|
|
|
int result = CreateHardLinkW(new_path, path, NULL) ? 0 : -1; |
|
|
|
if (result == -1) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
} else { |
|
|
|
SET_REQ_RESULT(req, result); |
|
|
|
} |
|
|
@ -726,13 +729,11 @@ void fs__symlink(uv_fs_t* req, const wchar_t* path, const wchar_t* new_path, |
|
|
|
path, |
|
|
|
flags & UV_FS_SYMLINK_DIR ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0) ? 0 : -1; |
|
|
|
if (result == -1) { |
|
|
|
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
req->result = -1; |
|
|
|
req->errorno = UV_ENOTSUP; |
|
|
|
req->last_error = ERROR_SUCCESS; |
|
|
|
SET_REQ_UV_ERROR(req, UV_ENOSYS, ERROR_NOT_SUPPORTED); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -761,7 +762,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { |
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == symlink) { |
|
|
|
result = -1; |
|
|
|
SET_REQ_LAST_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
@ -781,7 +782,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { |
|
|
|
|
|
|
|
if (!rv) { |
|
|
|
result = -1; |
|
|
|
SET_REQ_LAST_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
@ -789,7 +790,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { |
|
|
|
if (reparse_data->ReparseTag != IO_REPARSE_TAG_SYMLINK) { |
|
|
|
result = -1; |
|
|
|
/* something is seriously wrong */ |
|
|
|
SET_REQ_LAST_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
@ -810,7 +811,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { |
|
|
|
0); |
|
|
|
if (!utf8size) { |
|
|
|
result = -1; |
|
|
|
SET_REQ_LAST_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
@ -825,7 +826,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { |
|
|
|
utf8size); |
|
|
|
if (!utf8size) { |
|
|
|
result = -1; |
|
|
|
SET_REQ_LAST_ERROR(req, GetLastError()); |
|
|
|
SET_REQ_WIN32_ERROR(req, GetLastError()); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
|
|
|
|