[notmuch] [PATCH] Solaris doesn't have 'struct dirent::d_type'

Tomas Carnecky tom at dbservice.com
Sun Dec 20 05:20:32 PST 2009


Use stat(2) instead.

Signed-off-by: Tomas Carnecky <tom at dbservice.com>
---

There is a second issue that prevents notmuch from working on Solaris:
the getpwuid_r() prototype doesn't have the last argument. But that can
be easily worked around by setting -D_POSIX_PTHREAD_SEMANTICS on the
compiler commandline. Do you want to use uname to detect the platform
and define platform-specific code or can I unconditionally add that
define to CFLAGS?

 notmuch-new.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 9d20616..837ae4f 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -90,12 +90,18 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b)
  * Return 1 if the directory looks like a Maildir and 0 otherwise.
  */
 static int
-is_maildir (struct dirent **entries, int count)
+is_maildir (const char *path, struct dirent **entries, int count)
 {
     int i, found = 0;
 
     for (i = 0; i < count; i++) {
-	if (entries[i]->d_type != DT_DIR) continue;
+	char pbuf[PATH_MAX];
+        snprintf(pbuf, PATH_MAX, "%s/%s", path, entries[i]->d_name);
+
+	struct stat buf;
+	if (stat(pbuf, &buf) == -1 || !S_ISDIR(buf.st_mode))
+	    continue;
+
 	if (strcmp(entries[i]->d_name, "new") == 0 ||
 	    strcmp(entries[i]->d_name, "cur") == 0 ||
 	    strcmp(entries[i]->d_name, "tmp") == 0)
@@ -178,7 +184,13 @@ add_files_recursive (notmuch_database_t *notmuch,
 	/* If this directory hasn't been modified since the last
 	 * add_files, then we only need to look further for
 	 * sub-directories. */
-	if (path_mtime <= path_dbtime && entry->d_type == DT_REG)
+	struct stat buf;
+	char pbuf[PATH_MAX];
+	snprintf(pbuf, PATH_MAX, "%s/%s", path, entry->d_name);
+	if (stat(pbuf, &buf) == -1)
+	    continue;
+
+	if (path_mtime <= path_dbtime && S_ISREG(buf.st_mode))
 	    continue;
 
 	/* Ignore special directories to avoid infinite recursion.
@@ -188,9 +200,9 @@ add_files_recursive (notmuch_database_t *notmuch,
 	 * user specify files to be ignored. */
 	if (strcmp (entry->d_name, ".") == 0 ||
 	    strcmp (entry->d_name, "..") == 0 ||
-	    (entry->d_type == DT_DIR &&
+	    (S_ISDIR(buf.st_mode) &&
 	     (strcmp (entry->d_name, "tmp") == 0) &&
-	     is_maildir (namelist, num_entries)) ||
+	     is_maildir (path, namelist, num_entries)) ||
 	    strcmp (entry->d_name, ".notmuch") ==0)
 	{
 	    continue;
-- 
1.6.6.rc1.39.g9a42



More information about the notmuch mailing list