-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.rmdir on Windows throws ENOENT instead of ENOTDIR #18014
Comments
That error is reported by the operating system. There is not enough information for node.js/libuv to distinguish between 'path does not exist' and 'path is not a directory' without extra manual checks - but as that's prone to race conditions, libuv doesn't do that. To summarize: it's probably a wontfix. |
@bnoordhuis Using By the way, according to the documentation of |
I can't find the thread again but the issue was that diff --git a/deps/uv/src/win/error.c b/deps/uv/src/win/error.c
index 9b03bfef6b..1ec3d6e27f 100644
--- a/deps/uv/src/win/error.c
+++ b/deps/uv/src/win/error.c
@@ -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;
diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c
index 11c7c13edd..e4e4c58d7a 100644
--- a/deps/uv/src/win/fs.c
+++ b/deps/uv/src/win/fs.c
@@ -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());
+ }
}
|
@bnoordhuis That's exactly what I had in mind and it seems to work as expected: I am not sure whether this will have implications for other APIs, depending on whether Windows uses |
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: nodejs/node#18014
It might have been an XP-only issue or a buggy driver or something like that. Filed libuv/libuv#1698. |
Reverted for breaking `test/parallel/test-child-process-cwd.js` from the Node.js test suite. Instead of ENOENT when trying to remove a directory that does not exist, it started failing with ENOTDIR. This reverts commit 15f29dc. PR-URL: libuv#1717 Refs: nodejs/node#18014 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
See libuv/libuv@9f07a36, it was that it also returns I'm leaving this closed because I'm not going to revisit it. For anyone wanting to work on this, libuv is the place where the action happens. |
MSDN documents ERROR_DIRECTORY as |
It should throw ENOTDIR instead of ENOENT as there is an entry.
The text was updated successfully, but these errors were encountered: