@@ -1751,30 +1751,11 @@ int MKDirpAsync(uv_loop_t* loop,
17511751 return err;
17521752}
17531753
1754- int CallMKDirpSync (Environment* env, const FunctionCallbackInfo<Value>& args,
1755- FSReqWrapSync* req_wrap, const char * path, int mode) {
1756- env->PrintSyncTrace ();
1757- int err = MKDirpSync (env->event_loop (), &req_wrap->req , path, mode,
1758- nullptr );
1759- if (err < 0 ) {
1760- v8::Local<v8::Context> context = env->context ();
1761- v8::Local<v8::Object> ctx_obj = args[4 ].As <v8::Object>();
1762- v8::Isolate* isolate = env->isolate ();
1763- ctx_obj->Set (context,
1764- env->errno_string (),
1765- v8::Integer::New (isolate, err)).Check ();
1766- ctx_obj->Set (context,
1767- env->syscall_string (),
1768- OneByteString (isolate, " mkdir" )).Check ();
1769- }
1770- return err;
1771- }
1772-
17731754static void MKDir (const FunctionCallbackInfo<Value>& args) {
17741755 Environment* env = Environment::GetCurrent (args);
17751756
17761757 const int argc = args.Length ();
1777- CHECK_GE (argc, 4 );
1758+ CHECK_GE (argc, 3 );
17781759
17791760 BufferValue path (env->isolate (), args[0 ]);
17801761 CHECK_NOT_NULL (*path);
@@ -1787,37 +1768,39 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
17871768 CHECK (args[2 ]->IsBoolean ());
17881769 bool mkdirp = args[2 ]->IsTrue ();
17891770
1790- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
1791- if ( req_wrap_async != nullptr ) { // mkdir(path, mode, req)
1771+ if (argc > 3 ) { // mkdir(path, mode, recursive, req)
1772+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
17921773 FS_ASYNC_TRACE_BEGIN1 (
17931774 UV_FS_UNLINK, req_wrap_async, " path" , TRACE_STR_COPY (*path))
17941775 AsyncCall (env, req_wrap_async, args, " mkdir" , UTF8,
17951776 mkdirp ? AfterMkdirp : AfterNoArgs,
17961777 mkdirp ? MKDirpAsync : uv_fs_mkdir, *path, mode);
1797- } else { // mkdir(path, mode, undefined, ctx)
1798- CHECK_EQ (argc, 5 );
1799- FSReqWrapSync req_wrap_sync;
1778+ } else { // mkdir(path, mode, recursive)
1779+ FSReqWrapSync req_wrap_sync (" mkdir" , *path);
18001780 FS_SYNC_TRACE_BEGIN (mkdir);
18011781 if (mkdirp) {
1802- int err = CallMKDirpSync (env, args, &req_wrap_sync, *path, mode);
1803- if (err == 0 &&
1804- !req_wrap_sync.continuation_data ()->first_path ().empty ()) {
1782+ env->PrintSyncTrace ();
1783+ int err = MKDirpSync (
1784+ env->event_loop (), &req_wrap_sync.req , *path, mode, nullptr );
1785+ if (is_uv_error (err)) {
1786+ env->ThrowUVException (err, " mkdir" , nullptr , *path);
1787+ return ;
1788+ }
1789+ if (!req_wrap_sync.continuation_data ()->first_path ().empty ()) {
18051790 Local<Value> error;
18061791 std::string first_path (req_wrap_sync.continuation_data ()->first_path ());
18071792 FromNamespacedPath (&first_path);
18081793 MaybeLocal<Value> path = StringBytes::Encode (env->isolate (),
18091794 first_path.c_str (),
18101795 UTF8, &error);
18111796 if (path.IsEmpty ()) {
1812- Local<Object> ctx = args[4 ].As <Object>();
1813- ctx->Set (env->context (), env->error_string (), error).Check ();
1797+ env->isolate ()->ThrowException (error);
18141798 return ;
18151799 }
18161800 args.GetReturnValue ().Set (path.ToLocalChecked ());
18171801 }
18181802 } else {
1819- SyncCall (env, args[4 ], &req_wrap_sync, " mkdir" ,
1820- uv_fs_mkdir, *path, mode);
1803+ SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_mkdir, *path, mode);
18211804 }
18221805 FS_SYNC_TRACE_END (mkdir);
18231806 }
0 commit comments