فهرست منبع

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

Allen Wittenauer 9 سال پیش
والد
کامیت
5c24fe7f91

+ 3 - 0
hadoop-mapreduce-project/CHANGES.txt

@@ -214,6 +214,9 @@ Trunk (Unreleased)
     MAPREDUCE-6412. Make hadoop-mapreduce-client Native code -Wall-clean
     MAPREDUCE-6412. Make hadoop-mapreduce-client Native code -Wall-clean
     (Alan Burlison via aw)
     (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
   BREAKDOWN OF MAPREDUCE-2841 (NATIVE TASK) SUBTASKS
 
 
     MAPREDUCE-5985. native-task: Fix build on macosx. Contributed by
     MAPREDUCE-5985. native-task: Fix build on macosx. Contributed by

+ 8 - 1
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/native/src/lib/FileSystem.cc

@@ -167,10 +167,17 @@ class RawFileSystem : public FileSystem {
     FileEntry temp;
     FileEntry temp;
     while ((dirp = readdir(dp)) != NULL) {
     while ((dirp = readdir(dp)) != NULL) {
       temp.name = dirp->d_name;
       temp.name = dirp->d_name;
-      temp.isDirectory = dirp->d_type & DT_DIR;
       if (temp.name == "." || temp.name == "..") {
       if (temp.name == "." || temp.name == "..") {
         continue;
         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);
       status.push_back(temp);
     }
     }
     closedir(dp);
     closedir(dp);