Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve POSIX compliance in CLI/FileUtils.cpp #1064

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions CLI/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ static bool traverseDirectoryRec(const std::string& path, const std::function<vo
{
joinPaths(buf, path.c_str(), data.d_name);

int type = data.d_type;
int mode = -1;
#if defined(ATTOIF)
mode_t mode = ATTOIF(data.d_type);
#else
mode_t mode = 0;
#endif

// we need to stat DT_UNKNOWN to be able to tell the type
if (type == DT_UNKNOWN)
// we need to stat an UNKNOWN to be able to tell the type
if ((mode & S_IFMT) == 0)
{
struct stat st = {};
#ifdef _ATFILE_SOURCE
Expand All @@ -181,15 +184,15 @@ static bool traverseDirectoryRec(const std::string& path, const std::function<vo
mode = st.st_mode;
}

if (type == DT_DIR || mode == S_IFDIR)
if (mode & S_IFDIR)
{
traverseDirectoryRec(buf, callback);
}
else if (type == DT_REG || mode == S_IFREG)
else if (mode & S_IFREG)
{
callback(buf);
}
else if (type == DT_LNK || mode == S_IFLNK)
else if (mode & S_IFLNK)
{
// Skip symbolic links to avoid handling cycles
}
Expand Down