Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Coe <ben@npmjs.com>2018-08-10 02:52:41 +0300
committerBenjamin Coe <ben@npmjs.com>2018-08-11 22:07:32 +0300
commitbdef1b1eb45e2953e1ff68f0cc9a68ec83573e57 (patch)
treecf12dfaaa414432980c139066aa977ffc0724760 /src/node_file.h
parente0395247c899af101f8a1f76a8554be1ff14040a (diff)
fs: implement mkdir recursive (mkdirp)
Implements mkdirp functionality in node_file.cc. The Benefit of implementing in C++ layer is that the logic is more easily shared between the Promise and callback implementation and there are notable performance improvements. This commit is part of the Tooling Group Initiative. Refs: https://github.com/nodejs/user-feedback/pull/70 PR-URL: https://github.com/nodejs/node/pull/21875 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
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 fdd36efc775..af62be0feca 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)