Skip to content

Commit

Permalink
fs: throw rmdirSync errors in JS
Browse files Browse the repository at this point in the history
PR-URL: #18871
Refs: #18106
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
joyeecheung committed Feb 27, 2018
1 parent 29be1e5 commit 46164ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,17 +1004,21 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
static void RMDir(const FunctionCallbackInfo<Value>& 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);
}
}

Expand Down

0 comments on commit 46164ba

Please sign in to comment.