[PATCH 2/4] dirent->d_type not available on Soalris

Vladimir.Marek at oracle.com Vladimir.Marek at oracle.com
Mon Apr 9 03:17:43 PDT 2012


From: Vladimir Marek <vlmarek at volny.cz>

The inspiration was taken from similar issue in mutt:
http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html

Signed-off-by: Vladimir Marek <vlmarek at volny.cz>
---
 notmuch-new.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 4f13535..20bc580 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -21,6 +21,7 @@
 #include "notmuch-client.h"
 
 #include <unistd.h>
+#include <sys/types.h>
 
 typedef struct _filename_node {
     char *filename;
@@ -165,9 +166,12 @@ static int
 _entries_resemble_maildir (struct dirent **entries, int count)
 {
     int i, found = 0;
+    struct stat statbuf;
 
     for (i = 0; i < count; i++) {
-	if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
+	if (stat(entries[i]->d_name, &statbuf) == -1)
+		continue;
+	if (! S_ISDIR(statbuf.st_mode))
 	    continue;
 
 	if (strcmp(entries[i]->d_name, "new") == 0 ||
@@ -258,6 +262,7 @@ add_files_recursive (notmuch_database_t *notmuch,
     struct stat st;
     notmuch_bool_t is_maildir, new_directory;
     const char **tag;
+    struct stat statbuf;
 
     if (stat (path, &st)) {
 	fprintf (stderr, "Error reading directory %s: %s\n",
@@ -321,6 +326,9 @@ add_files_recursive (notmuch_database_t *notmuch,
 
 	entry = fs_entries[i];
 
+	if (stat(entry->d_name, &statbuf) == -1)
+		continue;
+
 	/* We only want to descend into directories.
 	 * But symlinks can be to directories too, of course.
 	 *
@@ -328,9 +336,8 @@ add_files_recursive (notmuch_database_t *notmuch,
 	 * scandir results, then it might be a directory (and if not,
 	 * then we'll stat and return immediately in the next level of
 	 * recursion). */
-	if (entry->d_type != DT_DIR &&
-	    entry->d_type != DT_LNK &&
-	    entry->d_type != DT_UNKNOWN)
+	if (!(statbuf.st_mode & S_IFDIR) &&
+	    !(statbuf.st_mode & S_IFLNK))
 	{
 	    continue;
 	}
@@ -427,7 +434,7 @@ add_files_recursive (notmuch_database_t *notmuch,
 	 *
 	 * In either case, a stat does the trick.
 	 */
-	if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
+	if (stat(entry->d_name, &statbuf) == -1 || statbuf.st_mode & S_IFLNK) {
 	    int err;
 
 	    next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
@@ -443,7 +450,7 @@ add_files_recursive (notmuch_database_t *notmuch,
 
 	    if (! S_ISREG (st.st_mode))
 		continue;
-	} else if (entry->d_type != DT_REG) {
+	} else if ( statbuf.st_mode & S_IFREG) {
 	    continue;
 	}
 
-- 
1.7.3.2



More information about the notmuch mailing list