From 46164ba2126095d4a788062003e3096699565efe Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 3 Feb 2018 21:39:43 +0800 Subject: [PATCH] fs: throw rmdirSync errors in JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/18871 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- lib/fs.js | 4 +++- src/node_file.cc | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 543e6b8c618..72770f371a9 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -748,7 +748,9 @@ fs.rmdir = function(path, callback) { fs.rmdirSync = function(path) { path = getPathFromURL(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) { diff --git a/src/node_file.cc b/src/node_file.cc index 1ef95134f39..5aa82a6a90c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1004,17 +1004,21 @@ static void Unlink(const FunctionCallbackInfo& args) { static void RMDir(const FunctionCallbackInfo& 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]); 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) { AsyncCall(env, req_wrap, args, "rmdir", UTF8, AfterNoArgs, uv_fs_rmdir, *path); - } else { - SYNC_CALL(rmdir, *path, *path) + } else { // rmdir(path, undefined, ctx) + CHECK_EQ(argc, 3); + fs_req_wrap req_wrap; + SyncCall(env, args[2], &req_wrap, "rmdir", + uv_fs_rmdir, *path); } }