fs: throw rmdirSync errors in JS

PR-URL: https://github.com/nodejs/node/pull/18871
Refs: https://github.com/nodejs/node/issues/18106
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Joyee Cheung 2018-02-03 21:39:43 +08:00
parent 29be1e5f84
commit 46164ba212
No known key found for this signature in database
GPG Key ID: F586868AAD831D0C
2 changed files with 11 additions and 5 deletions

View File

@ -748,7 +748,9 @@ fs.rmdir = function(path, callback) {
fs.rmdirSync = function(path) { fs.rmdirSync = function(path) {
path = getPathFromURL(path); path = getPathFromURL(path);
validatePath(path); validatePath(path);
return binding.rmdir(pathModule.toNamespacedPath(path)); const ctx = { path };
binding.rmdir(pathModule.toNamespacedPath(path), undefined, ctx);
handleErrorFromBinding(ctx);
}; };
fs.fdatasync = function(fd, callback) { fs.fdatasync = function(fd, callback) {

View File

@ -1004,17 +1004,21 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
static void RMDir(const FunctionCallbackInfo<Value>& args) { static void RMDir(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args); Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1); const int argc = args.Length();
CHECK_GE(argc, 2);
BufferValue path(env->isolate(), args[0]); BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr); CHECK_NE(*path, nullptr);
FSReqBase* req_wrap = GetReqWrap(env, args[1]); FSReqBase* req_wrap = GetReqWrap(env, args[1]); // rmdir(path, req)
if (req_wrap != nullptr) { if (req_wrap != nullptr) {
AsyncCall(env, req_wrap, args, "rmdir", UTF8, AfterNoArgs, AsyncCall(env, req_wrap, args, "rmdir", UTF8, AfterNoArgs,
uv_fs_rmdir, *path); uv_fs_rmdir, *path);
} else { } else { // rmdir(path, undefined, ctx)
SYNC_CALL(rmdir, *path, *path) CHECK_EQ(argc, 3);
fs_req_wrap req_wrap;
SyncCall(env, args[2], &req_wrap, "rmdir",
uv_fs_rmdir, *path);
} }
} }