@@ -1786,30 +1786,11 @@ int MKDirpAsync(uv_loop_t* loop,
17861786 return err;
17871787}
17881788
1789- int CallMKDirpSync (Environment* env, const FunctionCallbackInfo<Value>& args,
1790- FSReqWrapSync* req_wrap, const char * path, int mode) {
1791- env->PrintSyncTrace ();
1792- int err = MKDirpSync (env->event_loop (), &req_wrap->req , path, mode,
1793- nullptr );
1794- if (err < 0 ) {
1795- v8::Local<v8::Context> context = env->context ();
1796- v8::Local<v8::Object> ctx_obj = args[4 ].As <v8::Object>();
1797- v8::Isolate* isolate = env->isolate ();
1798- ctx_obj->Set (context,
1799- env->errno_string (),
1800- v8::Integer::New (isolate, err)).Check ();
1801- ctx_obj->Set (context,
1802- env->syscall_string (),
1803- OneByteString (isolate, " mkdir" )).Check ();
1804- }
1805- return err;
1806- }
1807-
18081789static void MKDir (const FunctionCallbackInfo<Value>& args) {
18091790 Environment* env = Environment::GetCurrent (args);
18101791
18111792 const int argc = args.Length ();
1812- CHECK_GE (argc, 4 );
1793+ CHECK_GE (argc, 3 );
18131794
18141795 BufferValue path (env->isolate (), args[0 ]);
18151796 CHECK_NOT_NULL (*path);
@@ -1822,37 +1803,39 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
18221803 CHECK (args[2 ]->IsBoolean ());
18231804 bool mkdirp = args[2 ]->IsTrue ();
18241805
1825- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
1826- if ( req_wrap_async != nullptr ) { // mkdir(path, mode, req)
1806+ if (argc > 3 ) { // mkdir(path, mode, recursive, req)
1807+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
18271808 FS_ASYNC_TRACE_BEGIN1 (
18281809 UV_FS_UNLINK, req_wrap_async, " path" , TRACE_STR_COPY (*path))
18291810 AsyncCall (env, req_wrap_async, args, " mkdir" , UTF8,
18301811 mkdirp ? AfterMkdirp : AfterNoArgs,
18311812 mkdirp ? MKDirpAsync : uv_fs_mkdir, *path, mode);
1832- } else { // mkdir(path, mode, undefined, ctx)
1833- CHECK_EQ (argc, 5 );
1834- FSReqWrapSync req_wrap_sync;
1813+ } else { // mkdir(path, mode, recursive)
1814+ FSReqWrapSync req_wrap_sync (" mkdir" , *path);
18351815 FS_SYNC_TRACE_BEGIN (mkdir);
18361816 if (mkdirp) {
1837- int err = CallMKDirpSync (env, args, &req_wrap_sync, *path, mode);
1838- if (err == 0 &&
1839- !req_wrap_sync.continuation_data ()->first_path ().empty ()) {
1817+ env->PrintSyncTrace ();
1818+ int err = MKDirpSync (
1819+ env->event_loop (), &req_wrap_sync.req , *path, mode, nullptr );
1820+ if (is_uv_error (err)) {
1821+ env->ThrowUVException (err, " mkdir" , nullptr , *path);
1822+ return ;
1823+ }
1824+ if (!req_wrap_sync.continuation_data ()->first_path ().empty ()) {
18401825 Local<Value> error;
18411826 std::string first_path (req_wrap_sync.continuation_data ()->first_path ());
18421827 FromNamespacedPath (&first_path);
18431828 MaybeLocal<Value> path = StringBytes::Encode (env->isolate (),
18441829 first_path.c_str (),
18451830 UTF8, &error);
18461831 if (path.IsEmpty ()) {
1847- Local<Object> ctx = args[4 ].As <Object>();
1848- ctx->Set (env->context (), env->error_string (), error).Check ();
1832+ env->isolate ()->ThrowException (error);
18491833 return ;
18501834 }
18511835 args.GetReturnValue ().Set (path.ToLocalChecked ());
18521836 }
18531837 } else {
1854- SyncCall (env, args[4 ], &req_wrap_sync, " mkdir" ,
1855- uv_fs_mkdir, *path, mode);
1838+ SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_mkdir, *path, mode);
18561839 }
18571840 FS_SYNC_TRACE_END (mkdir);
18581841 }
0 commit comments