@@ -1751,30 +1751,11 @@ int MKDirpAsync(uv_loop_t* loop,
1751
1751
return err;
1752
1752
}
1753
1753
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
-
1773
1754
static void MKDir (const FunctionCallbackInfo<Value>& args) {
1774
1755
Environment* env = Environment::GetCurrent (args);
1775
1756
1776
1757
const int argc = args.Length ();
1777
- CHECK_GE (argc, 4 );
1758
+ CHECK_GE (argc, 3 );
1778
1759
1779
1760
BufferValue path (env->isolate (), args[0 ]);
1780
1761
CHECK_NOT_NULL (*path);
@@ -1787,37 +1768,39 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
1787
1768
CHECK (args[2 ]->IsBoolean ());
1788
1769
bool mkdirp = args[2 ]->IsTrue ();
1789
1770
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 );
1792
1773
FS_ASYNC_TRACE_BEGIN1 (
1793
1774
UV_FS_UNLINK, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1794
1775
AsyncCall (env, req_wrap_async, args, " mkdir" , UTF8,
1795
1776
mkdirp ? AfterMkdirp : AfterNoArgs,
1796
1777
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);
1800
1780
FS_SYNC_TRACE_BEGIN (mkdir);
1801
1781
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 ()) {
1805
1790
Local<Value> error;
1806
1791
std::string first_path (req_wrap_sync.continuation_data ()->first_path ());
1807
1792
FromNamespacedPath (&first_path);
1808
1793
MaybeLocal<Value> path = StringBytes::Encode (env->isolate (),
1809
1794
first_path.c_str (),
1810
1795
UTF8, &error);
1811
1796
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);
1814
1798
return ;
1815
1799
}
1816
1800
args.GetReturnValue ().Set (path.ToLocalChecked ());
1817
1801
}
1818
1802
} 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);
1821
1804
}
1822
1805
FS_SYNC_TRACE_END (mkdir);
1823
1806
}
0 commit comments