Repository navigation
fs(readfile): merge open and fstat
#45314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b2df711
d86bb8b
99ab88c
b3ad214
61222b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -806,6 +806,31 @@ void AfterStat(uv_fs_t* req) { | |
| } | ||
| } | ||
|
|
||
| void OpenAndFstatAfterOpen(uv_fs_t* open_req) { | ||
| FSReqBase* req_wrap = FSReqBase::from_req(open_req); | ||
| int result = static_cast<int>(open_req->result); | ||
|
|
||
| FS_ASYNC_TRACE_END1( | ||
| open_req->fs_type, req_wrap, "result", result) | ||
|
|
||
| if (result < 0) { | ||
| FSReqAfterScope after(req_wrap, open_req); | ||
| req_wrap->Reject( | ||
| UVException(req_wrap->env()->isolate(), result, "open", nullptr, open_req->path)); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| char* fd = static_cast<char *>(open_req->data); | ||
| fd[0] = result; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| FS_ASYNC_TRACE_BEGIN0(UV_FS_FSTAT, req_wrap) | ||
| uv_fs_fstat(req_wrap->env()->event_loop(), | ||
| req_wrap->req(), | ||
| open_req->result, | ||
| AfterStat); | ||
| } | ||
|
|
||
| void AfterStatFs(uv_fs_t* req) { | ||
| FSReqBase* req_wrap = FSReqBase::from_req(req); | ||
| FSReqAfterScope after(req_wrap, req); | ||
|
|
@@ -2069,6 +2094,41 @@ static void Open(const FunctionCallbackInfo<Value>& args) { | |
| } | ||
| } | ||
|
|
||
| static void OpenAndFstat(const FunctionCallbackInfo<Value>& args) { | ||
| Environment* env = Environment::GetCurrent(args); | ||
|
|
||
| const int argc = args.Length(); | ||
| CHECK_GE(argc, 4); | ||
|
|
||
| BufferValue path(env->isolate(), args[0]); | ||
| CHECK_NOT_NULL(*path); | ||
|
|
||
| CHECK(args[1]->IsInt32()); | ||
| const int flags = args[1].As<Int32>()->Value(); | ||
|
|
||
| CHECK(args[2]->IsInt32()); | ||
| const int mode = args[2].As<Int32>()->Value(); | ||
|
|
||
| CHECK(Buffer::HasInstance(args[3])); | ||
| Local<Object> buffer_obj = args[3].As<Object>(); | ||
| char* fd_buffer = Buffer::Data(buffer_obj); | ||
|
|
||
| FSReqBase* req_wrap = GetReqWrap(args, 4, false); | ||
| if (req_wrap != nullptr) { | ||
| req_wrap->set_is_plain_open(true); | ||
| // Note: set fd in context | ||
| req_wrap->req()->data = fd_buffer; | ||
|
|
||
| FS_ASYNC_TRACE_BEGIN0(UV_FS_OPEN, req_wrap) | ||
| uv_fs_open(env->event_loop(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already tried But I'll try it again and yeah, maybe using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also remember that I've tried (in another branch) to change |
||
| req_wrap->req(), | ||
| *path, | ||
| flags, | ||
| mode, | ||
| OpenAndFstatAfterOpen); | ||
| } | ||
| } | ||
|
|
||
| static void OpenFileHandle(const FunctionCallbackInfo<Value>& args) { | ||
| Realm* realm = Realm::GetCurrent(args); | ||
| BindingData* binding_data = realm->GetBindingData<BindingData>(); | ||
|
|
@@ -3292,6 +3352,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |
|
|
||
| registry->Register(Close); | ||
| registry->Register(Open); | ||
| registry->Register(OpenAndFstat); | ||
| registry->Register(OpenFileHandle); | ||
| registry->Register(Read); | ||
| registry->Register(ReadBuffers); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls
uv_fs_req_cleanup()here. Where is that function called ifresult >= 0, i.e. when this conditional is not hit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably misunderstood something, but as we pass
req_wrap->req()to thefstatfunction, I thought that we should use theFSReqAfterScopeonly if we want to exit:openfstatcallbackAfterStatAm I correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
FSReqAfterScopewould destroy thereq_wrapobject; however, callinguv_fs_req_cleanup()is also an important part of what the function does, and if you don’t call it throughFSReqAfterScope, you should call it directly after the libuv call.