Skip to content

Fix _CFIterateDirectory behavior on some old file systems #1716

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

Merged
merged 1 commit into from
Oct 14, 2018
Merged
Changes from all 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: 17 additions & 0 deletions CoreFoundation/Base.subproj/CFFileUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,23 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
while ((dent = readdir(dirp))) {
#if DEPLOYMENT_TARGET_LINUX
CFIndex nameLen = strlen(dent->d_name);
if (dent->d_type == DT_UNKNOWN) {
// on some old file systems readdir may always fill d_type as DT_UNKNOWN (0), double check with stat
struct stat statBuf;
char pathToStat[sizeof(dent->d_name)];
strncpy(pathToStat, directoryPathBuf, sizeof(pathToStat));
strlcat(pathToStat, "/", sizeof(pathToStat));
strlcat(pathToStat, dent->d_name, sizeof(pathToStat));
if (stat(pathToStat, &statBuf) == 0) {
if (S_ISDIR(statBuf.st_mode)) {
dent->d_type = DT_DIR;
} else if (S_ISREG(statBuf.st_mode)) {
dent->d_type = DT_REG;
} else if (S_ISLNK(statBuf.st_mode)) {
dent->d_type = DT_LNK;
}
}
}
#else
CFIndex nameLen = dent->d_namlen;
#endif
Expand Down