@@ -1786,30 +1786,11 @@ int MKDirpAsync(uv_loop_t* loop,
1786
1786
return err;
1787
1787
}
1788
1788
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
-
1808
1789
static void MKDir (const FunctionCallbackInfo<Value>& args) {
1809
1790
Environment* env = Environment::GetCurrent (args);
1810
1791
1811
1792
const int argc = args.Length ();
1812
- CHECK_GE (argc, 4 );
1793
+ CHECK_GE (argc, 3 );
1813
1794
1814
1795
BufferValue path (env->isolate (), args[0 ]);
1815
1796
CHECK_NOT_NULL (*path);
@@ -1822,37 +1803,39 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
1822
1803
CHECK (args[2 ]->IsBoolean ());
1823
1804
bool mkdirp = args[2 ]->IsTrue ();
1824
1805
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 );
1827
1808
FS_ASYNC_TRACE_BEGIN1 (
1828
1809
UV_FS_UNLINK, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1829
1810
AsyncCall (env, req_wrap_async, args, " mkdir" , UTF8,
1830
1811
mkdirp ? AfterMkdirp : AfterNoArgs,
1831
1812
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);
1835
1815
FS_SYNC_TRACE_BEGIN (mkdir);
1836
1816
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 ()) {
1840
1825
Local<Value> error;
1841
1826
std::string first_path (req_wrap_sync.continuation_data ()->first_path ());
1842
1827
FromNamespacedPath (&first_path);
1843
1828
MaybeLocal<Value> path = StringBytes::Encode (env->isolate (),
1844
1829
first_path.c_str (),
1845
1830
UTF8, &error);
1846
1831
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);
1849
1833
return ;
1850
1834
}
1851
1835
args.GetReturnValue ().Set (path.ToLocalChecked ());
1852
1836
}
1853
1837
} 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);
1856
1839
}
1857
1840
FS_SYNC_TRACE_END (mkdir);
1858
1841
}
0 commit comments