<p><br>
On Apr 9, 2012 1:18 PM, <<a href="mailto:Vladimir.Marek@oracle.com">Vladimir.Marek@oracle.com</a>> wrote:<br>
><br>
> From: Vladimir Marek <<a href="mailto:vlmarek@volny.cz">vlmarek@volny.cz</a>><br>
><br>
> The inspiration was taken from similar issue in mutt:<br>
> <a href="http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html">http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html</a><br>
><br>
> Signed-off-by: Vladimir Marek <<a href="mailto:vlmarek@volny.cz">vlmarek@volny.cz</a>><br>
> ---<br>
> notmuch-new.c | 19 +++++++++++++------<br>
> 1 files changed, 13 insertions(+), 6 deletions(-)<br>
><br>
> diff --git a/notmuch-new.c b/notmuch-new.c<br>
> index 4f13535..20bc580 100644<br>
> --- a/notmuch-new.c<br>
> +++ b/notmuch-new.c<br>
> @@ -21,6 +21,7 @@<br>
> #include "notmuch-client.h"<br>
><br>
> #include <unistd.h><br>
> +#include <sys/types.h><br>
><br>
> typedef struct _filename_node {<br>
> char *filename;<br>
> @@ -165,9 +166,12 @@ static int<br>
> _entries_resemble_maildir (struct dirent **entries, int count)<br>
> {<br>
> int i, found = 0;<br>
> + struct stat statbuf;<br>
><br>
> for (i = 0; i < count; i++) {<br>
> - if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)<br>
> + if (stat(entries[i]->d_name, &statbuf) == -1)<br>
> + continue;<br>
> + if (! S_ISDIR(statbuf.st_mode))</p>
<p>Notmuch new is possibly one of the most performance critical bits for people with, uh, much mail. The performance impact of the new syscalls should be measured. (Can't do this myself atm.)</p>
<p>BR,<br>
Jani. <br></p>
<p>> continue;<br>
><br>
> if (strcmp(entries[i]->d_name, "new") == 0 ||<br>
> @@ -258,6 +262,7 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
> struct stat st;<br>
> notmuch_bool_t is_maildir, new_directory;<br>
> const char **tag;<br>
> + struct stat statbuf;<br>
><br>
> if (stat (path, &st)) {<br>
> fprintf (stderr, "Error reading directory %s: %s\n",<br>
> @@ -321,6 +326,9 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
><br>
> entry = fs_entries[i];<br>
><br>
> + if (stat(entry->d_name, &statbuf) == -1)<br>
> + continue;<br>
> +<br>
> /* We only want to descend into directories.<br>
> * But symlinks can be to directories too, of course.<br>
> *<br>
> @@ -328,9 +336,8 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
> * scandir results, then it might be a directory (and if not,<br>
> * then we'll stat and return immediately in the next level of<br>
> * recursion). */<br>
> - if (entry->d_type != DT_DIR &&<br>
> - entry->d_type != DT_LNK &&<br>
> - entry->d_type != DT_UNKNOWN)<br>
> + if (!(statbuf.st_mode & S_IFDIR) &&<br>
> + !(statbuf.st_mode & S_IFLNK))<br>
> {<br>
> continue;<br>
> }<br>
> @@ -427,7 +434,7 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
> *<br>
> * In either case, a stat does the trick.<br>
> */<br>
> - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {<br>
> + if (stat(entry->d_name, &statbuf) == -1 || statbuf.st_mode & S_IFLNK) {<br>
> int err;<br>
><br>
> next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);<br>
> @@ -443,7 +450,7 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
><br>
> if (! S_ISREG (st.st_mode))<br>
> continue;<br>
> - } else if (entry->d_type != DT_REG) {<br>
> + } else if ( statbuf.st_mode & S_IFREG) {<br>
> continue;<br>
> }<br>
><br>
> --<br>
> 1.7.3.2<br>
><br>
> _______________________________________________<br>
> notmuch mailing list<br>
> <a href="mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a><br>
> <a href="http://notmuchmail.org/mailman/listinfo/notmuch">http://notmuchmail.org/mailman/listinfo/notmuch</a><br>
</p>