win: use RemoveDirectoryW() instead of _wmrmdir()
Use RemoveDirectoryW() and remap ERROR_DIRECTORY from UV_ENOENT to UV_ENOTDIR so that attempted removal of a non-directory produces the right (and legible) error message. Fixes: https://github.com/nodejs/node/issues/18014 PR-URL: https://github.com/libuv/libuv/pull/1698 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
634bcc3164
commit
15f29dc08f
@ -131,7 +131,7 @@ int uv_translate_sys_error(int sys_errno) {
|
||||
case WSAENETUNREACH: return UV_ENETUNREACH;
|
||||
case WSAENOBUFS: return UV_ENOBUFS;
|
||||
case ERROR_BAD_PATHNAME: return UV_ENOENT;
|
||||
case ERROR_DIRECTORY: return UV_ENOENT;
|
||||
case ERROR_DIRECTORY: return UV_ENOTDIR;
|
||||
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
|
||||
case ERROR_INVALID_NAME: return UV_ENOENT;
|
||||
case ERROR_INVALID_DRIVE: return UV_ENOENT;
|
||||
|
||||
@ -723,8 +723,11 @@ void fs__write(uv_fs_t* req) {
|
||||
|
||||
|
||||
void fs__rmdir(uv_fs_t* req) {
|
||||
int result = _wrmdir(req->file.pathw);
|
||||
SET_REQ_RESULT(req, result);
|
||||
if (RemoveDirectoryW(req->file.pathw)) {
|
||||
SET_REQ_SUCCESS(req);
|
||||
} else {
|
||||
SET_REQ_WIN32_ERROR(req, GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -469,10 +469,19 @@ static void mkdtemp_cb(uv_fs_t* req) {
|
||||
static void rmdir_cb(uv_fs_t* req) {
|
||||
ASSERT(req == &rmdir_req);
|
||||
ASSERT(req->fs_type == UV_FS_RMDIR);
|
||||
ASSERT(req->result == 0);
|
||||
rmdir_cb_count++;
|
||||
ASSERT(req->path);
|
||||
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
|
||||
switch (rmdir_cb_count++) {
|
||||
default:
|
||||
ASSERT(0);
|
||||
case 0:
|
||||
ASSERT(req->result == UV_ENOTDIR);
|
||||
ASSERT(memcmp(req->path, "test_dir/file1\0", 15) == 0);
|
||||
break;
|
||||
case 1:
|
||||
ASSERT(req->result == 0);
|
||||
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
|
||||
break;
|
||||
}
|
||||
uv_fs_req_cleanup(req);
|
||||
}
|
||||
|
||||
@ -986,6 +995,11 @@ TEST_IMPL(fs_async_dir) {
|
||||
|
||||
ASSERT(stat_cb_count == 4);
|
||||
|
||||
r = uv_fs_rmdir(loop, &rmdir_req, "test_dir/file1", rmdir_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
ASSERT(rmdir_cb_count == 1);
|
||||
|
||||
r = uv_fs_unlink(loop, &unlink_req, "test_dir/file1", unlink_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
@ -999,7 +1013,7 @@ TEST_IMPL(fs_async_dir) {
|
||||
r = uv_fs_rmdir(loop, &rmdir_req, "test_dir", rmdir_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
ASSERT(rmdir_cb_count == 1);
|
||||
ASSERT(rmdir_cb_count == 2);
|
||||
|
||||
/* Cleanup */
|
||||
unlink("test_dir/file1");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user