[notmuch] [PATCH] d_type fix
authorGeo Carncross <geocar-notmuch@internetconnection.net>
Thu, 21 Jan 2010 20:10:18 +0000 (15:10 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:01 +0000 (09:36 -0800)
d2/7c13342fd0ed10c9af5ab0ae87313d0762c86c [new file with mode: 0644]

diff --git a/d2/7c13342fd0ed10c9af5ab0ae87313d0762c86c b/d2/7c13342fd0ed10c9af5ab0ae87313d0762c86c
new file mode 100644 (file)
index 0000000..7f006f1
--- /dev/null
@@ -0,0 +1,115 @@
+Return-Path: <geocar-notmuch@internetconnection.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 C6542431FBD\r
+       for <notmuch@notmuchmail.org>; Thu, 21 Jan 2010 12:16:56 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.001\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.001 tagged_above=-999 required=5\r
+       tests=[BAYES_50=0.001] autolearn=ham\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 gd4UzekXOLka for <notmuch@notmuchmail.org>;\r
+       Thu, 21 Jan 2010 12:16:56 -0800 (PST)\r
+X-Greylist: delayed 400 seconds by postgrey-1.32 at olra;\r
+       Thu, 21 Jan 2010 12:16:55 PST\r
+Received: from proxy.dmvnoc.com (proxy.dmvnoc.com [216.169.144.254])\r
+       by olra.theworths.org (Postfix) with ESMTP id E6EAC431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 21 Jan 2010 12:16:55 -0800 (PST)\r
+Received: (qmail 11079 invoked from network); 21 Jan 2010 20:10:14 +0000\r
+Received: from unknown (HELO ?192.168.1.19?) (192.168.1.19)\r
+       by mail.internetconnection.net with SMTP; 21 Jan 2010 20:10:14 +0000\r
+From: Geo Carncross <geocar-notmuch@internetconnection.net>\r
+To: notmuch@notmuchmail.org\r
+Content-Type: multipart/mixed; boundary="=-M4CpZ46nwdpaYw2E2ppA"\r
+Date: Thu, 21 Jan 2010 15:10:18 -0500\r
+Message-ID: <1264104618.3941.108.camel@dwarf>\r
+Mime-Version: 1.0\r
+X-Mailer: Evolution 2.28.1 \r
+Subject: [notmuch] [PATCH] d_type fix\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: Thu, 21 Jan 2010 20:16:57 -0000\r
+\r
+\r
+--=-M4CpZ46nwdpaYw2E2ppA\r
+Content-Type: text/plain; charset="UTF-8"\r
+Content-Transfer-Encoding: 7bit\r
+\r
+A review of notmuch-new.c shows three uses of ->d_type:\r
+\r
+Near line 153, in _entries_resemble_maildir() we can simply allow for\r
+DT_UNKNOWN. This would fail if people have MH-style folders which have\r
+three folders called "new" "cur" and "tmp", but that seems unlikely, in\r
+which case the "tmp" folder would simply not be scanned.\r
+\r
+Near line 273 in add_files_recursive() we have another check. If\r
+DT_UNKNOWN, we fall through, then add_files_recursive() does a stat\r
+almost immediately, returning with success if the path isn't a\r
+directory.\r
+\r
+Thus, the fallback is already written.\r
+\r
+Finally, near line 343, in add_files_recursive() (a long function) we\r
+have another check. Here we can simply treat DT_UNKNOWN as DT_LNK, since\r
+the logic for the stat() results are the same.\r
+\r
+Attached is a patch which was tested with reiserfs. It should also work\r
+with xfs.\r
+\r
+\r
+\r
+--=-M4CpZ46nwdpaYw2E2ppA\r
+Content-Disposition: attachment; filename="notmuch_new_d_type_fix.patch"\r
+Content-Type: text/x-patch; name="notmuch_new_d_type_fix.patch";\r
+ charset="UTF-8"\r
+Content-Transfer-Encoding: 7bit\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index b740ee2..3e6b96a 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -153,7 +153,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+     int i, found = 0;\r
\r
+     for (i = 0; i < count; i++) {\r
+-      if (entries[i]->d_type != DT_DIR)\r
++      if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)\r
+           continue;\r
\r
+       if (strcmp(entries[i]->d_name, "new") == 0 ||\r
+@@ -273,7 +273,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
\r
+       entry = fs_entries[i];\r
\r
+-      if (entry->d_type != DT_DIR && entry->d_type != DT_LNK)\r
++      if (entry->d_type != DT_DIR && entry->d_type != DT_LNK\r
++                      && entry->d_type != DT_UNKNOWN)\r
+           continue;\r
\r
+       /* Ignore special directories to avoid infinite recursion.\r
+@@ -343,7 +344,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
\r
+       /* If we're looking at a symlink, we only want to add it if it\r
+        * links to a regular file, (and not to a directory, say). */\r
+-      if (entry->d_type == DT_LNK) {\r
++      if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {\r
+           int err;\r
\r
+           next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+\r
+--=-M4CpZ46nwdpaYw2E2ppA--\r
+\r