diff options
author | bcoe <bencoe@google.com> | 2020-01-29 10:06:44 +0300 |
---|---|---|
committer | Benjamin Coe <bencoe@google.com> | 2020-01-31 22:57:19 +0300 |
commit | 13fe56bbbbc290cbc16804994ce0ec1d25729775 (patch) | |
tree | 08d6e7fea79a897d44256b011165c5f7c3c988c0 /src/node_file.h | |
parent | 43fb6ffef7a14b47d1b0ba8134102795f5017a59 (diff) |
fs: return first folder made by mkdir recursive
mkdir('/foo/bar', { recursive: true }) and mkdirSync will now return
the path of the first folder created. This matches more closely
mkdirp's behavior, and is useful for setting folder permissions.
PR-URL: https://github.com/nodejs/node/pull/31530
Refs: https://github.com/nodejs/node/issues/31481
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_file.h')
-rw-r--r-- | src/node_file.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/node_file.h b/src/node_file.h index 0574aa8f6c0..1ebfe06c1fb 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -19,10 +19,13 @@ class FSContinuationData : public MemoryRetainer { inline void PushPath(std::string&& path); inline void PushPath(const std::string& path); inline std::string PopPath(); + // Used by mkdirp to track the first path created: + inline void MaybeSetFirstPath(const std::string& path); inline void Done(int result); int mode() const { return mode_; } const std::vector<std::string>& paths() const { return paths_; } + const std::string& first_path() const { return first_path_; } void MemoryInfo(MemoryTracker* tracker) const override; SET_MEMORY_INFO_NAME(FSContinuationData) @@ -33,6 +36,7 @@ class FSContinuationData : public MemoryRetainer { uv_fs_t* req_; int mode_; std::vector<std::string> paths_; + std::string first_path_; }; class FSReqBase : public ReqWrap<uv_fs_t> { @@ -306,8 +310,18 @@ class FSReqWrapSync { ~FSReqWrapSync() { uv_fs_req_cleanup(&req); } uv_fs_t req; + FSContinuationData* continuation_data() const { + return continuation_data_.get(); + } + void set_continuation_data(std::unique_ptr<FSContinuationData> data) { + continuation_data_ = std::move(data); + } + FSReqWrapSync(const FSReqWrapSync&) = delete; FSReqWrapSync& operator=(const FSReqWrapSync&) = delete; + + private: + std::unique_ptr<FSContinuationData> continuation_data_; }; // TODO(addaleax): Currently, callers check the return value and assume |