MAPREDUCE-6416. Not all platforms have d_type in struct dirent (Alan Burlison via aw)

This commit is contained in:
Allen Wittenauer 2015-10-27 12:22:08 -07:00
parent ab99d953e4
commit 5c24fe7f91
2 changed files with 11 additions and 1 deletions

View File

@ -214,6 +214,9 @@ Trunk (Unreleased)
MAPREDUCE-6412. Make hadoop-mapreduce-client Native code -Wall-clean
(Alan Burlison via aw)
MAPREDUCE-6416. Not all platforms have d_type in struct dirent
(Alan Burlison via aw)
BREAKDOWN OF MAPREDUCE-2841 (NATIVE TASK) SUBTASKS
MAPREDUCE-5985. native-task: Fix build on macosx. Contributed by

View File

@ -167,10 +167,17 @@ class RawFileSystem : public FileSystem {
FileEntry temp;
while ((dirp = readdir(dp)) != NULL) {
temp.name = dirp->d_name;
temp.isDirectory = dirp->d_type & DT_DIR;
if (temp.name == "." || temp.name == "..") {
continue;
}
/* Use Linux d_type if available, otherwise stat(2) the path */
#ifdef DT_DIR
temp.isDirectory = dirp->d_type & DT_DIR;
#else
const string p = path + "/" + temp.name;
struct stat sb;
temp.isDirectory = stat(p.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode) == 0;
#endif
status.push_back(temp);
}
closedir(dp);