Skip to content

Commit

Permalink
fs: return errno and take fs_req_wrap in SyncCall
Browse files Browse the repository at this point in the history
PR-URL: #17914
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Jan 16, 2018
1 parent 316b5ef commit 791975d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Func, typename... Args>
inline void SyncCall(Environment* env, Local<Value> ctx,
inline int SyncCall(Environment* env, Local<Value> 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> context = env->context();
Local<Object> ctx_obj = ctx->ToObject(context).ToLocalChecked();
Expand All @@ -391,6 +390,7 @@ inline void SyncCall(Environment* env, Local<Value> ctx,
env->syscall_string(),
OneByteString(isolate, syscall)).FromJust();
}
return err;
}

#define SYNC_DEST_CALL(func, path, dest, ...) \
Expand Down Expand Up @@ -426,7 +426,8 @@ void Access(const FunctionCallbackInfo<Value>& 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);
}
}

Expand All @@ -446,7 +447,8 @@ void Close(const FunctionCallbackInfo<Value>& 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);
}
}

Expand Down

0 comments on commit 791975d

Please sign in to comment.