From: Vladimir Marek <vlmarek@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@volny.cz> --- notmuch-new.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 4f13535..3d265bd 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -21,6 +21,9 @@ #include "notmuch-client.h" #include <unistd.h> +#ifndef _DIRENT_HAVE_D_TYPE +#include <sys/types.h> +#endif typedef struct _filename_node { char *filename; @@ -167,7 +170,14 @@ _entries_resemble_maildir (struct dirent **entries, int count) int i, found = 0; for (i = 0; i < count; i++) { +#ifdef _DIRENT_HAVE_D_TYPE if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN) +#else + struct stat statbuf; + if (stat(entries[i]->d_name, &statbuf) == -1) + continue; + if (! S_ISDIR(statbuf.st_mode)) +#endif continue; if (strcmp(entries[i]->d_name, "new") == 0 || @@ -258,6 +268,9 @@ add_files_recursive (notmuch_database_t *notmuch, struct stat st; notmuch_bool_t is_maildir, new_directory; const char **tag; +#ifndef _DIRENT_HAVE_D_TYPE + struct stat statbuf; +#endif if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -328,9 +341,16 @@ 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). */ +#ifdef _DIRENT_HAVE_D_TYPE if (entry->d_type != DT_DIR && entry->d_type != DT_LNK && entry->d_type != DT_UNKNOWN) +#else + if (stat(entry->d_name, &statbuf) == -1) + continue; + if (!(statbuf.st_mode & S_IFDIR) && + !(statbuf.st_mode & S_IFLNK)) +#endif { continue; } @@ -427,7 +447,11 @@ add_files_recursive (notmuch_database_t *notmuch, * * In either case, a stat does the trick. */ +#ifdef _DIRENT_HAVE_D_TYPE if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) { +#else + if (stat(entry->d_name, &statbuf) == -1 || statbuf.st_mode & S_IFLNK) { +#endif int err; next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); @@ -443,7 +467,11 @@ add_files_recursive (notmuch_database_t *notmuch, if (! S_ISREG (st.st_mode)) continue; +#ifdef _DIRENT_HAVE_D_TYPE } else if (entry->d_type != DT_REG) { +#else + } else if (statbuf.st_mode & S_IFREG) { +#endif continue; } -- 1.7.3.2