summaryrefslogtreecommitdiff
path: root/src/node_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_file.cc')
-rw-r--r--src/node_file.cc92
1 files changed, 69 insertions, 23 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 48b382986c..577b9c7c41 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -18,7 +18,8 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-#include "node_file.h"
+#include "node_file.h" // NOLINT(build/include_inline)
+#include "node_file-inl.h"
#include "aliased_buffer.h"
#include "memory_tracker-inl.h"
#include "node_buffer.h"
@@ -107,6 +108,19 @@ inline int64_t GetOffset(Local<Value> value) {
// functions, and thus does not wrap them properly.
typedef void(*uv_fs_callback_t)(uv_fs_t*);
+
+void FSContinuationData::MemoryInfo(MemoryTracker* tracker) const {
+ tracker->TrackField("paths", paths_);
+}
+
+FileHandleReadWrap::~FileHandleReadWrap() {}
+
+FSReqBase::~FSReqBase() {}
+
+void FSReqBase::MemoryInfo(MemoryTracker* tracker) const {
+ tracker->TrackField("continuation_data", continuation_data_);
+}
+
// The FileHandle object wraps a file descriptor and will close it on garbage
// collection if necessary. If that happens, a process warning will be
// emitted (or a fatal exception will occur if the fd cannot be closed.)
@@ -156,6 +170,16 @@ FileHandle::~FileHandle() {
CHECK(closed_); // We have to be closed at the point
}
+int FileHandle::DoWrite(WriteWrap* w,
+ uv_buf_t* bufs,
+ size_t count,
+ uv_stream_t* send_handle) {
+ return UV_ENOSYS; // Not implemented (yet).
+}
+
+void FileHandle::MemoryInfo(MemoryTracker* tracker) const {
+ tracker->TrackField("current_read", current_read_);
+}
// Close the file descriptor if it hasn't already been closed. A process
// warning will be emitted using a SetImmediate to avoid calling back to
@@ -225,12 +249,34 @@ FileHandle* FileHandle::CloseReq::file_handle() {
return Unwrap<FileHandle>(obj);
}
+FileHandle::CloseReq::CloseReq(Environment* env,
+ Local<Object> obj,
+ Local<Promise> promise,
+ Local<Value> ref)
+ : ReqWrap(env, obj, AsyncWrap::PROVIDER_FILEHANDLECLOSEREQ) {
+ promise_.Reset(env->isolate(), promise);
+ ref_.Reset(env->isolate(), ref);
+}
+
+FileHandle::CloseReq::~CloseReq() {
+ uv_fs_req_cleanup(req());
+ promise_.Reset();
+ ref_.Reset();
+}
+
+void FileHandle::CloseReq::MemoryInfo(MemoryTracker* tracker) const {
+ tracker->TrackField("promise", promise_);
+ tracker->TrackField("ref", ref_);
+}
+
+
+
// Closes this FileHandle asynchronously and returns a Promise that will be
// resolved when the callback is invoked, or rejects with a UVException if
// there was a problem closing the fd. This is the preferred mechanism for
// closing the FD object even tho the object will attempt to close
// automatically on gc.
-inline MaybeLocal<Promise> FileHandle::ClosePromise() {
+MaybeLocal<Promise> FileHandle::ClosePromise() {
Isolate* isolate = env()->isolate();
EscapableHandleScope scope(isolate);
Local<Context> context = env()->context();
@@ -1157,13 +1203,13 @@ int MKDirpSync(uv_loop_t* loop,
FSContinuationData continuation_data(req, mode, cb);
continuation_data.PushPath(std::move(path));
- while (continuation_data.paths.size() > 0) {
+ while (continuation_data.paths().size() > 0) {
std::string next_path = continuation_data.PopPath();
int err = uv_fs_mkdir(loop, req, next_path.c_str(), mode, nullptr);
while (true) {
switch (err) {
case 0:
- if (continuation_data.paths.size() == 0) {
+ if (continuation_data.paths().size() == 0) {
return 0;
}
break;
@@ -1173,7 +1219,7 @@ int MKDirpSync(uv_loop_t* loop,
if (dirname != next_path) {
continuation_data.PushPath(std::move(next_path));
continuation_data.PushPath(std::move(dirname));
- } else if (continuation_data.paths.size() == 0) {
+ } else if (continuation_data.paths().size() == 0) {
err = UV_EEXIST;
continue;
}
@@ -1188,7 +1234,7 @@ int MKDirpSync(uv_loop_t* loop,
err = uv_fs_stat(loop, req, next_path.c_str(), nullptr);
if (err == 0 && !S_ISDIR(req->statbuf.st_mode)) {
uv_fs_req_cleanup(req);
- if (orig_err == UV_EEXIST && continuation_data.paths.size() > 0) {
+ if (orig_err == UV_EEXIST && continuation_data.paths().size() > 0) {
return UV_ENOTDIR;
}
return UV_EEXIST;
@@ -1211,14 +1257,14 @@ int MKDirpAsync(uv_loop_t* loop,
uv_fs_cb cb) {
FSReqBase* req_wrap = FSReqBase::from_req(req);
// on the first iteration of algorithm, stash state information.
- if (req_wrap->continuation_data == nullptr) {
- req_wrap->continuation_data =
- std::make_unique<FSContinuationData>(req, mode, cb);
- req_wrap->continuation_data->PushPath(std::move(path));
+ if (req_wrap->continuation_data() == nullptr) {
+ req_wrap->set_continuation_data(
+ std::make_unique<FSContinuationData>(req, mode, cb));
+ req_wrap->continuation_data()->PushPath(std::move(path));
}
// on each iteration of algorithm, mkdir directory on top of stack.
- std::string next_path = req_wrap->continuation_data->PopPath();
+ std::string next_path = req_wrap->continuation_data()->PopPath();
int err = uv_fs_mkdir(loop, req, next_path.c_str(), mode,
uv_fs_callback_t{[](uv_fs_t* req) {
FSReqBase* req_wrap = FSReqBase::from_req(req);
@@ -1230,12 +1276,12 @@ int MKDirpAsync(uv_loop_t* loop,
while (true) {
switch (err) {
case 0: {
- if (req_wrap->continuation_data->paths.size() == 0) {
- req_wrap->continuation_data->Done(0);
+ if (req_wrap->continuation_data()->paths().size() == 0) {
+ req_wrap->continuation_data()->Done(0);
} else {
uv_fs_req_cleanup(req);
MKDirpAsync(loop, req, path.c_str(),
- req_wrap->continuation_data->mode, nullptr);
+ req_wrap->continuation_data()->mode(), nullptr);
}
break;
}
@@ -1243,19 +1289,19 @@ int MKDirpAsync(uv_loop_t* loop,
std::string dirname = path.substr(0,
path.find_last_of(kPathSeparator));
if (dirname != path) {
- req_wrap->continuation_data->PushPath(std::move(path));
- req_wrap->continuation_data->PushPath(std::move(dirname));
- } else if (req_wrap->continuation_data->paths.size() == 0) {
+ req_wrap->continuation_data()->PushPath(std::move(path));
+ req_wrap->continuation_data()->PushPath(std::move(dirname));
+ } else if (req_wrap->continuation_data()->paths().size() == 0) {
err = UV_EEXIST;
continue;
}
uv_fs_req_cleanup(req);
MKDirpAsync(loop, req, path.c_str(),
- req_wrap->continuation_data->mode, nullptr);
+ req_wrap->continuation_data()->mode(), nullptr);
break;
}
case UV_EPERM: {
- req_wrap->continuation_data->Done(err);
+ req_wrap->continuation_data()->Done(err);
break;
}
default:
@@ -1267,14 +1313,14 @@ int MKDirpAsync(uv_loop_t* loop,
FSReqBase* req_wrap = FSReqBase::from_req(req);
int err = req->result;
if (reinterpret_cast<intptr_t>(req->data) == UV_EEXIST &&
- req_wrap->continuation_data->paths.size() > 0) {
+ req_wrap->continuation_data()->paths().size() > 0) {
if (err == 0 && S_ISDIR(req->statbuf.st_mode)) {
Environment* env = req_wrap->env();
uv_loop_t* loop = env->event_loop();
std::string path = req->path;
uv_fs_req_cleanup(req);
MKDirpAsync(loop, req, path.c_str(),
- req_wrap->continuation_data->mode, nullptr);
+ req_wrap->continuation_data()->mode(), nullptr);
return;
}
err = UV_ENOTDIR;
@@ -1282,9 +1328,9 @@ int MKDirpAsync(uv_loop_t* loop,
// verify that the path pointed to is actually a directory.
if (err == 0 && !S_ISDIR(req->statbuf.st_mode)) err = UV_EEXIST;
uv_fs_req_cleanup(req);
- req_wrap->continuation_data->Done(err);
+ req_wrap->continuation_data()->Done(err);
}});
- if (err < 0) req_wrap->continuation_data->Done(err);
+ if (err < 0) req_wrap->continuation_data()->Done(err);
break;
}
break;