diff options
author | bcoe <bencoe@google.com> | 2020-01-25 09:12:39 +0300 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-17 22:36:51 +0300 |
commit | 8669ecc8a2b2f1f836a790c0fd5b57805575f95c (patch) | |
tree | 830f0983d6ab802572e67ce2a0446c903598eadb /src/node_file.cc | |
parent | a2b7006847d8339977014af0863fa071c7314353 (diff) |
fs: bail on permission error in recursive directory creation
When creating directories recursively, the logic should bail
immediately on UV_EACCES and bubble the error to the user.
PR-URL: https://github.com/nodejs/node/pull/31505
Fixes: https://github.com/nodejs/node/issues/31481
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_file.cc')
-rw-r--r-- | src/node_file.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index fbab726afb4..8d43b0ef662 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1226,11 +1226,17 @@ int MKDirpSync(uv_loop_t* loop, int err = uv_fs_mkdir(loop, req, next_path.c_str(), mode, nullptr); while (true) { switch (err) { + // Note: uv_fs_req_cleanup in terminal paths will be called by + // ~FSReqWrapSync(): case 0: if (continuation_data.paths().size() == 0) { return 0; } break; + case UV_EACCES: + case UV_EPERM: { + return err; + } case UV_ENOENT: { std::string dirname = next_path.substr(0, next_path.find_last_of(kPathSeparator)); @@ -1243,9 +1249,6 @@ int MKDirpSync(uv_loop_t* loop, } break; } - case UV_EPERM: { - return err; - } default: uv_fs_req_cleanup(req); int orig_err = err; @@ -1293,6 +1296,8 @@ int MKDirpAsync(uv_loop_t* loop, while (true) { switch (err) { + // Note: uv_fs_req_cleanup in terminal paths will be called by + // FSReqAfterScope::~FSReqAfterScope() case 0: { if (req_wrap->continuation_data()->paths().size() == 0) { req_wrap->continuation_data()->Done(0); @@ -1303,6 +1308,11 @@ int MKDirpAsync(uv_loop_t* loop, } break; } + case UV_EACCES: + case UV_EPERM: { + req_wrap->continuation_data()->Done(err); + break; + } case UV_ENOENT: { std::string dirname = path.substr(0, path.find_last_of(kPathSeparator)); @@ -1318,10 +1328,6 @@ int MKDirpAsync(uv_loop_t* loop, req_wrap->continuation_data()->mode(), nullptr); break; } - case UV_EPERM: { - req_wrap->continuation_data()->Done(err); - break; - } default: uv_fs_req_cleanup(req); // Stash err for use in the callback. |