src: use S_ISDIR
to check if the file is a directory
PR-URL: https://github.com/nodejs/node/pull/52164 Fixes: https://github.com/nodejs/node/issues/52159 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e2697c1a64
commit
6ddf590ed1
@ -1054,7 +1054,7 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
|
|||||||
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
|
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
||||||
rc = !!(s->st_mode & S_IFDIR);
|
rc = S_ISDIR(s->st_mode);
|
||||||
}
|
}
|
||||||
uv_fs_req_cleanup(&req);
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
@ -2982,7 +2982,7 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
|
|||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
||||||
rc = !!(s->st_mode & S_IFDIR);
|
rc = S_ISDIR(s->st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_fs_req_cleanup(&req);
|
uv_fs_req_cleanup(&req);
|
||||||
|
@ -21,7 +21,7 @@ std::string WildcardIfDir(const std::string& res) noexcept {
|
|||||||
int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr);
|
int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
|
||||||
if (s->st_mode & S_IFDIR) {
|
if ((s->st_mode & S_IFMT) == S_IFDIR) {
|
||||||
// add wildcard when directory
|
// add wildcard when directory
|
||||||
if (res.back() == node::kPathSeparator) {
|
if (res.back() == node::kPathSeparator) {
|
||||||
return res + "*";
|
return res + "*";
|
||||||
|
14
test/parallel/test-fs-readdir-recursive.js
Normal file
14
test/parallel/test-fs-readdir-recursive.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const fs = require('fs');
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
tmpdir.refresh();
|
||||||
|
|
||||||
|
const server = net.createServer().listen(common.PIPE, common.mustCall(() => {
|
||||||
|
// The process should not crash
|
||||||
|
// See https://github.com/nodejs/node/issues/52159
|
||||||
|
fs.readdirSync(tmpdir.path, { recursive: true });
|
||||||
|
server.close();
|
||||||
|
}));
|
Loading…
x
Reference in New Issue
Block a user