Re: [PATCH 2/4] dirent->d_type not available on Soalris
authorJani Nikula <jani@nikula.org>
Mon, 9 Apr 2012 11:17:21 +0000 (14:17 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:10 +0000 (09:46 -0800)
d1/917e0181a8db6794719d38310e0ae4f229cd57 [new file with mode: 0644]

diff --git a/d1/917e0181a8db6794719d38310e0ae4f229cd57 b/d1/917e0181a8db6794719d38310e0ae4f229cd57
new file mode 100644 (file)
index 0000000..fae396c
--- /dev/null
@@ -0,0 +1,310 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E24ED414B99\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 04:17:23 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id sPq+F+Txzq6B for <notmuch@notmuchmail.org>;\r
+       Mon,  9 Apr 2012 04:17:22 -0700 (PDT)\r
+Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
+       [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A8E0A414B96\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 04:17:22 -0700 (PDT)\r
+Received: by pbcuo1 with SMTP id uo1so5664086pbc.26\r
+       for <notmuch@notmuchmail.org>; Mon, 09 Apr 2012 04:17:22 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=mime-version:in-reply-to:references:date:message-id:subject:from:to\r
+       :cc:content-type:x-gm-message-state;\r
+       bh=E+XhC5NXOKVzDJcPVfP59TOgg4Ulya0BCUPpoIzpbPo=;\r
+       b=kRWJRVqNH/Z/gP2XTu4t4E2ze92asyFc1PZkORF5CeQqQUia1FOma/wyAwTapeEwFC\r
+       9+Gl4nHpCI3tjML9P/10jbtuqWYeeRTQpvgIjZV4i2mGLKp1OlZaADHcsfYx3kAG7gM1\r
+       8gpw6dWkI32xveQZb5Gr5B8ZHSz41wqlQQnpmSNpE2vcAFxkr63bmqeF8bqdNnBP/EPD\r
+       9TnkkOg7zxLSQmhM/ycmQ59f56gneSAb+QfA6FaXXZFY66MoVGIX2a4HmOy+ERi+h5cy\r
+       uxlcScnCg3uY2Iu39PVU2WvSteytNLkIqtEKuCj1en+dHmSRVm2PAjQJREuf1BKO36C6\r
+       eM+w==\r
+MIME-Version: 1.0\r
+Received: by 10.68.223.36 with SMTP id qr4mr6141349pbc.54.1333970241762; Mon,\r
+       09 Apr 2012 04:17:21 -0700 (PDT)\r
+Received: by 10.68.241.234 with HTTP; Mon, 9 Apr 2012 04:17:21 -0700 (PDT)\r
+Received: by 10.68.241.234 with HTTP; Mon, 9 Apr 2012 04:17:21 -0700 (PDT)\r
+In-Reply-To: <1333966665-10469-3-git-send-email-Vladimir.Marek@oracle.com>\r
+References: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com>\r
+       <1333966665-10469-3-git-send-email-Vladimir.Marek@oracle.com>\r
+Date: Mon, 9 Apr 2012 14:17:21 +0300\r
+Message-ID:\r
+ <CAB+hUn_gFp+bspNFa-4e6hnH077Sx3to8jZGo1MSwt82QFwxwQ@mail.gmail.com>\r
+Subject: Re: [PATCH 2/4] dirent->d_type not available on Soalris\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Vladimir.Marek@oracle.com\r
+Content-Type: multipart/alternative; boundary=047d7b2e09bd66b3a104bd3d2610\r
+X-Gm-Message-State:\r
+ ALoCoQn/5FrY6tb5qa1fPucNshwvazO+3HkQ/jO3eKVmUcZIlXykxJPu43ANXX0rrAOxqspGSz9s\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>, Vladimir Marek <vlmarek@volny.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 09 Apr 2012 11:17:24 -0000\r
+\r
+--047d7b2e09bd66b3a104bd3d2610\r
+Content-Type: text/plain; charset=UTF-8\r
+\r
+On Apr 9, 2012 1:18 PM, <Vladimir.Marek@oracle.com> wrote:\r
+>\r
+> From: Vladimir Marek <vlmarek@volny.cz>\r
+>\r
+> The inspiration was taken from similar issue in mutt:\r
+> http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html\r
+>\r
+> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
+> ---\r
+>  notmuch-new.c |   19 +++++++++++++------\r
+>  1 files changed, 13 insertions(+), 6 deletions(-)\r
+>\r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index 4f13535..20bc580 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -21,6 +21,7 @@\r
+>  #include "notmuch-client.h"\r
+>\r
+>  #include <unistd.h>\r
+> +#include <sys/types.h>\r
+>\r
+>  typedef struct _filename_node {\r
+>     char *filename;\r
+> @@ -165,9 +166,12 @@ static int\r
+>  _entries_resemble_maildir (struct dirent **entries, int count)\r
+>  {\r
+>     int i, found = 0;\r
+> +    struct stat statbuf;\r
+>\r
+>     for (i = 0; i < count; i++) {\r
+> -       if (entries[i]->d_type != DT_DIR && entries[i]->d_type !=\r
+DT_UNKNOWN)\r
+> +       if (stat(entries[i]->d_name, &statbuf) == -1)\r
+> +               continue;\r
+> +       if (! S_ISDIR(statbuf.st_mode))\r
+\r
+Notmuch new is possibly one of the most performance critical bits for\r
+people with, uh, much mail. The performance impact of the new syscalls\r
+should be measured. (Can't do this myself atm.)\r
+\r
+BR,\r
+Jani.\r
+\r
+>            continue;\r
+>\r
+>        if (strcmp(entries[i]->d_name, "new") == 0 ||\r
+> @@ -258,6 +262,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>     struct stat st;\r
+>     notmuch_bool_t is_maildir, new_directory;\r
+>     const char **tag;\r
+> +    struct stat statbuf;\r
+>\r
+>     if (stat (path, &st)) {\r
+>        fprintf (stderr, "Error reading directory %s: %s\n",\r
+> @@ -321,6 +326,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>\r
+>        entry = fs_entries[i];\r
+>\r
+> +       if (stat(entry->d_name, &statbuf) == -1)\r
+> +               continue;\r
+> +\r
+>        /* We only want to descend into directories.\r
+>         * But symlinks can be to directories too, of course.\r
+>         *\r
+> @@ -328,9 +336,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>         * scandir results, then it might be a directory (and if not,\r
+>         * then we'll stat and return immediately in the next level of\r
+>         * recursion). */\r
+> -       if (entry->d_type != DT_DIR &&\r
+> -           entry->d_type != DT_LNK &&\r
+> -           entry->d_type != DT_UNKNOWN)\r
+> +       if (!(statbuf.st_mode & S_IFDIR) &&\r
+> +           !(statbuf.st_mode & S_IFLNK))\r
+>        {\r
+>            continue;\r
+>        }\r
+> @@ -427,7 +434,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>         *\r
+>         * In either case, a stat does the trick.\r
+>         */\r
+> -       if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {\r
+> +       if (stat(entry->d_name, &statbuf) == -1 || statbuf.st_mode &\r
+S_IFLNK) {\r
+>            int err;\r
+>\r
+>            next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+> @@ -443,7 +450,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>\r
+>            if (! S_ISREG (st.st_mode))\r
+>                continue;\r
+> -       } else if (entry->d_type != DT_REG) {\r
+> +       } else if ( statbuf.st_mode & S_IFREG) {\r
+>            continue;\r
+>        }\r
+>\r
+> --\r
+> 1.7.3.2\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--047d7b2e09bd66b3a104bd3d2610\r
+Content-Type: text/html; charset=UTF-8\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+<p><br>\r
+On Apr 9, 2012 1:18 PM, &lt;<a href=3D"mailto:Vladimir.Marek@oracle.com">Vl=\r
+adimir.Marek@oracle.com</a>&gt; wrote:<br>\r
+&gt;<br>\r
+&gt; From: Vladimir Marek &lt;<a href=3D"mailto:vlmarek@volny.cz">vlmarek@v=\r
+olny.cz</a>&gt;<br>\r
+&gt;<br>\r
+&gt; The inspiration was taken from similar issue in mutt:<br>\r
+&gt; <a href=3D"http://does-not-exist.org/mail-archives/mutt-dev/msg11290.h=\r
+tml">http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html</a><br>\r
+&gt;<br>\r
+&gt; Signed-off-by: Vladimir Marek &lt;<a href=3D"mailto:vlmarek@volny.cz">=\r
+vlmarek@volny.cz</a>&gt;<br>\r
+&gt; ---<br>\r
+&gt; =C2=A0notmuch-new.c | =C2=A0 19 +++++++++++++------<br>\r
+&gt; =C2=A01 files changed, 13 insertions(+), 6 deletions(-)<br>\r
+&gt;<br>\r
+&gt; diff --git a/notmuch-new.c b/notmuch-new.c<br>\r
+&gt; index 4f13535..20bc580 100644<br>\r
+&gt; --- a/notmuch-new.c<br>\r
+&gt; +++ b/notmuch-new.c<br>\r
+&gt; @@ -21,6 +21,7 @@<br>\r
+&gt; =C2=A0#include &quot;notmuch-client.h&quot;<br>\r
+&gt;<br>\r
+&gt; =C2=A0#include &lt;unistd.h&gt;<br>\r
+&gt; +#include &lt;sys/types.h&gt;<br>\r
+&gt;<br>\r
+&gt; =C2=A0typedef struct _filename_node {<br>\r
+&gt; =C2=A0 =C2=A0 char *filename;<br>\r
+&gt; @@ -165,9 +166,12 @@ static int<br>\r
+&gt; =C2=A0_entries_resemble_maildir (struct dirent **entries, int count)<b=\r
+r>\r
+&gt; =C2=A0{<br>\r
+&gt; =C2=A0 =C2=A0 int i, found =3D 0;<br>\r
+&gt; + =C2=A0 =C2=A0struct stat statbuf;<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 for (i =3D 0; i &lt; count; i++) {<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 if (entries[i]-&gt;d_type !=3D DT_DIR &amp;&amp=\r
+; entries[i]-&gt;d_type !=3D DT_UNKNOWN)<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 if (stat(entries[i]-&gt;d_name, &amp;statbuf) =\r
+=3D=3D -1)<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 if (! S_ISDIR(statbuf.st_mode))</p>\r
+<p>Notmuch new is possibly one of the most performance critical bits for pe=\r
+ople with, uh, much mail. The performance impact of the new syscalls should=\r
+ be measured. (Can&#39;t do this myself atm.)</p>\r
+<p>BR,<br>\r
+Jani. <br></p>\r
+<p>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0if (strcmp(entries[i]-&gt;d_name, &quot;new=\r
+&quot;) =3D=3D 0 ||<br>\r
+&gt; @@ -258,6 +262,7 @@ add_files_recursive (notmuch_database_t *notmuch,<=\r
+br>\r
+&gt; =C2=A0 =C2=A0 struct stat st;<br>\r
+&gt; =C2=A0 =C2=A0 notmuch_bool_t is_maildir, new_directory;<br>\r
+&gt; =C2=A0 =C2=A0 const char **tag;<br>\r
+&gt; + =C2=A0 =C2=A0struct stat statbuf;<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 if (stat (path, &amp;st)) {<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf (stderr, &quot;Error reading direct=\r
+ory %s: %s\n&quot;,<br>\r
+&gt; @@ -321,6 +326,9 @@ add_files_recursive (notmuch_database_t *notmuch,<=\r
+br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0entry =3D fs_entries[i];<br>\r
+&gt;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 if (stat(entry-&gt;d_name, &amp;statbuf) =3D=3D=\r
+ -1)<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>\r
+&gt; +<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0/* We only want to descend into directories=\r
+.<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 * But symlinks can be to directories too, =\r
+of course.<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 *<br>\r
+&gt; @@ -328,9 +336,8 @@ add_files_recursive (notmuch_database_t *notmuch,<=\r
+br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 * scandir results, then it might be a dire=\r
+ctory (and if not,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 * then we&#39;ll stat and return immediate=\r
+ly in the next level of<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 * recursion). */<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 if (entry-&gt;d_type !=3D DT_DIR &amp;&amp;<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry-&gt;d_type !=3D DT_LNK &amp=\r
+;&amp;<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry-&gt;d_type !=3D DT_UNKNOWN)=\r
+<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 if (!(statbuf.st_mode &amp; S_IFDIR) &amp;&amp;=\r
+<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 !(statbuf.st_mode &amp; S_IFLNK))=\r
+<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0{<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>\r
+&gt; @@ -427,7 +434,7 @@ add_files_recursive (notmuch_database_t *notmuch,<=\r
+br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 *<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 * In either case, a stat does the trick.<b=\r
+r>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 */<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 if (entry-&gt;d_type =3D=3D DT_LNK || entry-&gt=\r
+;d_type =3D=3D DT_UNKNOWN) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 if (stat(entry-&gt;d_name, &amp;statbuf) =3D=3D=\r
+ -1 || statbuf.st_mode &amp; S_IFLNK) {<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int err;<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0next =3D talloc_asprintf (not=\r
+much, &quot;%s/%s&quot;, path, entry-&gt;d_name);<br>\r
+&gt; @@ -443,7 +450,7 @@ add_files_recursive (notmuch_database_t *notmuch,<=\r
+br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (! S_ISREG (st.st_mode))<b=\r
+r>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>\r
+&gt; - =C2=A0 =C2=A0 =C2=A0 } else if (entry-&gt;d_type !=3D DT_REG) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 } else if ( statbuf.st_mode &amp; S_IFREG) {<br=\r
+>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>\r
+&gt;<br>\r
+&gt; --<br>\r
+&gt; 1.7.3.2<br>\r
+&gt;<br>\r
+&gt; _______________________________________________<br>\r
+&gt; notmuch mailing list<br>\r
+&gt; <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=\r
+<br>\r
+&gt; <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=\r
+muchmail.org/mailman/listinfo/notmuch</a><br>\r
+</p>\r
+\r
+--047d7b2e09bd66b3a104bd3d2610--\r