From 791975d1895c1b037d539d9191d4e60a6fdf0c5d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 28 Dec 2017 04:01:12 +0800 Subject: [PATCH] fs: return errno and take fs_req_wrap in SyncCall PR-URL: https://github.com/nodejs/node/pull/17914 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- src/node_file.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index a7581099f6b0e6..4566f08c1a6454 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -375,11 +375,10 @@ inline FSReqWrap* AsyncCall(Environment* env, // the error number and the syscall in the context instead of // creating an error in the C++ land. template -inline void SyncCall(Environment* env, Local ctx, +inline int SyncCall(Environment* env, Local ctx, fs_req_wrap* req_wrap, const char* syscall, Func fn, Args... args) { - fs_req_wrap req_wrap; env->PrintSyncTrace(); - int err = fn(env->event_loop(), &req_wrap.req, args..., nullptr); + int err = fn(env->event_loop(), &(req_wrap->req), args..., nullptr); if (err < 0) { Local context = env->context(); Local ctx_obj = ctx->ToObject(context).ToLocalChecked(); @@ -391,6 +390,7 @@ inline void SyncCall(Environment* env, Local ctx, env->syscall_string(), OneByteString(isolate, syscall)).FromJust(); } + return err; } #define SYNC_DEST_CALL(func, path, dest, ...) \ @@ -426,7 +426,8 @@ void Access(const FunctionCallbackInfo& args) { AsyncCall(env, args, "access", UTF8, AfterNoArgs, uv_fs_access, *path, mode); } else { // access(path, mode, undefined, ctx) - SyncCall(env, args[3], "access", uv_fs_access, *path, mode); + fs_req_wrap req_wrap; + SyncCall(env, args[3], &req_wrap, "access", uv_fs_access, *path, mode); } } @@ -446,7 +447,8 @@ void Close(const FunctionCallbackInfo& args) { AsyncCall(env, args, "close", UTF8, AfterNoArgs, uv_fs_close, fd); } else { // close(fd, undefined, ctx) - SyncCall(env, args[2], "close", uv_fs_close, fd); + fs_req_wrap req_wrap; + SyncCall(env, args[2], &req_wrap, "close", uv_fs_close, fd); } }