[notmuch] [PATCH] Solaris doesn't have 'struct dirent::d_type'
authorJames Westby <jw+debian@jameswestby.net>
Sun, 20 Dec 2009 18:02:47 +0000 (18:02 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:54 +0000 (09:35 -0800)
a3/c19278f6c7c1b6c823eb375785523e8256fcf3 [new file with mode: 0644]

diff --git a/a3/c19278f6c7c1b6c823eb375785523e8256fcf3 b/a3/c19278f6c7c1b6c823eb375785523e8256fcf3
new file mode 100644 (file)
index 0000000..c3c7c95
--- /dev/null
@@ -0,0 +1,162 @@
+Return-Path: <james@jameswestby.net>\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 38807431FBF\r
+       for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 10:03:00 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 P5HV5whxHL7W for <notmuch@notmuchmail.org>;\r
+       Sun, 20 Dec 2009 10:02:56 -0800 (PST)\r
+Received: from jameswestby.net (jameswestby.net [89.145.97.141])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9D8F5431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 10:02:56 -0800 (PST)\r
+Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com\r
+       ([94.169.116.60] helo=flash)\r
+       by jameswestby.net with esmtpa (Exim 4.69)\r
+       (envelope-from <james@jameswestby.net>)\r
+       id 1NMQ7K-0000Rc-N7; Sun, 20 Dec 2009 18:02:54 +0000\r
+Received: by flash (Postfix, from userid 1000)\r
+       id AF70B6E546A; Sun, 20 Dec 2009 18:02:48 +0000 (GMT)\r
+From: James Westby <jw+debian@jameswestby.net>\r
+To: notmuch@notmuchmail.org\r
+Date: Sun, 20 Dec 2009 18:02:47 +0000\r
+Message-Id: <1261332167-17994-1-git-send-email-jw+debian@jameswestby.net>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1261315232-21494-1-git-send-email-tom@dbservice.com>\r
+References: <1261315232-21494-1-git-send-email-tom@dbservice.com>\r
+Subject: [notmuch] [PATCH] Solaris doesn't have 'struct dirent::d_type'\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Sun, 20 Dec 2009 18:03:00 -0000\r
+\r
+From: Tomas Carnecky <tom@dbservice.com>\r
+\r
+Use stat(2) instead.\r
+\r
+Signed-off-by: Tomas Carnecky <tom@dbservice.com>\r
+Signed-off-by: James Westby <jw+debian@jameswestby.net>\r
+---\r
+\r
+  The original patch duplicated asprintf and stat calls, rearraging\r
+  the code means we don't need to.\r
+\r
+  I have a concern about the duplicated stats in is_maildir, but they\r
+  are not so easy to save. I ran a quick timing test (3931 files), dropping\r
+  caches before each set:\r
+\r
+    master:\r
+      real  2m3.545s\r
+      real  1m34.571s\r
+      real  1m36.005s\r
+\r
+    original patch:\r
+      real  2m18.114s\r
+      real  1m34.843s\r
+      real  1m36.317s\r
+\r
+    revised patch:\r
+      real  2m5.890s\r
+      real  1m36.387s\r
+      real  1m36.453s\r
+\r
+  This shoes there is little impact of the code, but given that it is\r
+  around one percent we may want to make it conditional on platform\r
+  and save the extra stat calls.\r
+\r
+  Thanks,\r
+\r
+  James\r
+\r
+ notmuch-new.c |   46 ++++++++++++++++++++++++++--------------------\r
+ 1 files changed, 26 insertions(+), 20 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 9d20616..c6f4963 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -90,12 +90,18 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
+  * Return 1 if the directory looks like a Maildir and 0 otherwise.\r
+  */\r
+ static int\r
+-is_maildir (struct dirent **entries, int count)\r
++is_maildir (const char *path, struct dirent **entries, int count)\r
+ {\r
+     int i, found = 0;\r
\r
+     for (i = 0; i < count; i++) {\r
+-      if (entries[i]->d_type != DT_DIR) continue;\r
++      char pbuf[PATH_MAX];\r
++        snprintf(pbuf, PATH_MAX, "%s/%s", path, entries[i]->d_name);\r
++\r
++      struct stat buf;\r
++      if (stat(pbuf, &buf) == -1 || !S_ISDIR(buf.st_mode))\r
++          continue;\r
++\r
+       if (strcmp(entries[i]->d_name, "new") == 0 ||\r
+           strcmp(entries[i]->d_name, "cur") == 0 ||\r
+           strcmp(entries[i]->d_name, "tmp") == 0)\r
+@@ -178,24 +184,6 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+       /* If this directory hasn't been modified since the last\r
+        * add_files, then we only need to look further for\r
+        * sub-directories. */\r
+-      if (path_mtime <= path_dbtime && entry->d_type == DT_REG)\r
+-          continue;\r
+-\r
+-      /* Ignore special directories to avoid infinite recursion.\r
+-       * Also ignore the .notmuch directory.\r
+-       */\r
+-      /* XXX: Eventually we'll want more sophistication to let the\r
+-       * user specify files to be ignored. */\r
+-      if (strcmp (entry->d_name, ".") == 0 ||\r
+-          strcmp (entry->d_name, "..") == 0 ||\r
+-          (entry->d_type == DT_DIR &&\r
+-           (strcmp (entry->d_name, "tmp") == 0) &&\r
+-           is_maildir (namelist, num_entries)) ||\r
+-          strcmp (entry->d_name, ".notmuch") ==0)\r
+-      {\r
+-          continue;\r
+-      }\r
+-\r
+       next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
\r
+       if (stat (next, st)) {\r
+@@ -216,6 +204,24 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+           goto DONE;\r
+       }\r
\r
++      if (path_mtime <= path_dbtime && S_ISREG(st->st_mode))\r
++          continue;\r
++\r
++      /* Ignore special directories to avoid infinite recursion.\r
++       * Also ignore the .notmuch directory.\r
++       */\r
++      /* XXX: Eventually we'll want more sophistication to let the\r
++       * user specify files to be ignored. */\r
++      if (strcmp (entry->d_name, ".") == 0 ||\r
++          strcmp (entry->d_name, "..") == 0 ||\r
++          (S_ISDIR(st->st_mode) &&\r
++           (strcmp (entry->d_name, "tmp") == 0) &&\r
++           is_maildir (path, namelist, num_entries)) ||\r
++          strcmp (entry->d_name, ".notmuch") ==0)\r
++      {\r
++          continue;\r
++      }\r
++\r
+       if (S_ISREG (st->st_mode)) {\r
+           /* If the file hasn't been modified since the last\r
+            * add_files, then we need not look at it. */\r
+-- \r
+1.6.3.3\r
+\r