summaryrefslogtreecommitdiff
path: root/src/node_file.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_file.h')
-rw-r--r--src/node_file.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/node_file.h b/src/node_file.h
index fdd36efc77..af62be0fec 100644
--- a/src/node_file.h
+++ b/src/node_file.h
@@ -21,10 +21,50 @@ using v8::Value;
namespace fs {
+// structure used to store state during a complex operation, e.g., mkdirp.
+class FSContinuationData : public MemoryRetainer {
+ public:
+ FSContinuationData(uv_fs_t* req, int mode, uv_fs_cb done_cb)
+ : req(req), mode(mode), done_cb(done_cb) {
+ }
+
+ uv_fs_t* req;
+ int mode;
+ std::vector<std::string> paths;
+
+ void PushPath(std::string&& path) {
+ paths.emplace_back(std::move(path));
+ }
+
+ void PushPath(const std::string& path) {
+ paths.push_back(path);
+ }
+
+ std::string PopPath() {
+ CHECK_GT(paths.size(), 0);
+ std::string path = std::move(paths.back());
+ paths.pop_back();
+ return path;
+ }
+
+ void Done(int result) {
+ req->result = result;
+ done_cb(req);
+ }
+
+ void MemoryInfo(MemoryTracker* tracker) const override {
+ tracker->TrackThis(this);
+ tracker->TrackField("paths", paths);
+ }
+
+ private:
+ uv_fs_cb done_cb;
+};
class FSReqBase : public ReqWrap<uv_fs_t> {
public:
typedef MaybeStackBuffer<char, 64> FSReqBuffer;
+ std::unique_ptr<FSContinuationData> continuation_data = nullptr;
FSReqBase(Environment* env, Local<Object> req, AsyncWrap::ProviderType type,
bool use_bigint)
@@ -97,6 +137,7 @@ class FSReqCallback : public FSReqBase {
void MemoryInfo(MemoryTracker* tracker) const override {
tracker->TrackThis(this);
+ tracker->TrackField("continuation_data", continuation_data);
}
ADD_MEMORY_INFO_NAME(FSReqCallback)
@@ -162,6 +203,7 @@ class FSReqPromise : public FSReqBase {
void MemoryInfo(MemoryTracker* tracker) const override {
tracker->TrackThis(this);
tracker->TrackField("stats_field_array", stats_field_array_);
+ tracker->TrackField("continuation_data", continuation_data);
}
ADD_MEMORY_INFO_NAME(FSReqPromise)