Re: [notmuch] Subject: [PATCH] update the check whether a dir entry should be ignored.
authorDirk-Jan C. Binnema <djcb.bulk@gmail.com>
Sat, 12 Dec 2009 16:45:49 +0000 (18:45 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:52 +0000 (09:35 -0800)
56/1dcad1ba07fddc18ff4c50fed8ae21422184af [new file with mode: 0644]

diff --git a/56/1dcad1ba07fddc18ff4c50fed8ae21422184af b/56/1dcad1ba07fddc18ff4c50fed8ae21422184af
new file mode 100644 (file)
index 0000000..ae22c12
--- /dev/null
@@ -0,0 +1,180 @@
+Return-Path: <djcb@djcbsoftware.nl>\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 03BAF431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 12 Dec 2009 08:46:10 -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 TR2VLImoolbx for <notmuch@notmuchmail.org>;\r
+       Sat, 12 Dec 2009 08:46:08 -0800 (PST)\r
+Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi\r
+       [195.197.172.115])\r
+       by olra.theworths.org (Postfix) with ESMTP id 99CB8431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 12 Dec 2009 08:46:08 -0800 (PST)\r
+Received: from djcbsoftware.nl (a88-112-254-208.elisa-laajakaista.fi\r
+       [88.112.254.208])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by gw01.mail.saunalahti.fi (Postfix) with ESMTP id 4A48F1514B5;\r
+       Sat, 12 Dec 2009 18:46:05 +0200 (EET)\r
+Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])\r
+       by djcbsoftware.nl (Postfix) with ESMTP id 502EB39C0D8;\r
+       Sat, 12 Dec 2009 18:46:03 +0200 (EET)\r
+Date: Sat, 12 Dec 2009 18:45:49 +0200\r
+Message-ID: <87my1ocf9e.wl%djcb@djcbsoftware.nl>\r
+From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>\r
+To: David Maus <maus.david@gmail.com>\r
+In-Reply-To: <874onwfizh.wl%maus.david@gmail.com>\r
+References: <87r5r0ctl3.wl%djcb@djcbsoftware.nl>\r
+       <874onwfizh.wl%maus.david@gmail.com>\r
+Mail-Reply-To: djcb@djcbsoftware.nl\r
+User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0\r
+       (HANACHIRUSATO)\r
+Organization: DJCBSoftware\r
+MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")\r
+Content-Type: text/plain; charset=US-ASCII\r
+Cc: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>\r
+Subject: Re: [notmuch] Subject: [PATCH] update the check whether a dir\r
+       entry   should be ignored.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+Reply-To: djcb@djcbsoftware.nl\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: Sat, 12 Dec 2009 16:46:10 -0000\r
+\r
+Hi David,\r
+\r
+>>>>> "DM" == David Maus <maus.david@gmail.com> writes:\r
+\r
+    >> There is one maybe controversial change, namely that it ignores all\r
+    >> dot-dirs; this works fine for .notmuch and .nnmaildir (gnus), but maybe\r
+    >> there is some valid use case for having mail in dot-dirs. Maybe one of\r
+    >> the IMAP-servers does this? Not sure. Anyway, I can change that part.\r
+\r
+    DM> Yes, ignore dot-dirs completely is not a good idea as the "." is a\r
+    DM> common separator for mailbox hierarchies on imap servers. Dovecot uses\r
+    DM> it by default, Courier too.\r
+\r
+Thanks. I was suspecting something like that. Attached, updated patch that\r
+also updates the counting part.\r
+\r
+---\r
+ notmuch-new.c |   75 ++++++++++++++++++++++++++++++++++++++-------------------\r
+ 1 files changed, 50 insertions(+), 25 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 9d20616..411e084 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -109,6 +109,44 @@ is_maildir (struct dirent **entries, int count)\r
+     return 0;\r
+ }\r
\r
++\r
++static int\r
++ignore_dir_entry (const char* path, struct dirent *entry)\r
++{\r
++    char noindex[4096]; /* any path will fit */\r
++    \r
++    /* ignore everything starting with a dot; this covers hidden\r
++    * files, as well as special dir (. and ..), but also things like\r
++    * gnus .nnmaildir or .notmuch */\r
++\r
++    /* special handling for dot-dirs */\r
++    if (entry->d_name[0] == '.') {\r
++\r
++      /* ignore '.' and '..' */\r
++      if (entry->d_name[1] == '\0' ||\r
++          (entry->d_name[1] == '.' && entry->d_name[2] == '\0')) \r
++          return 1;\r
++      \r
++      if (entry->d_name[1] == 'n')  { /* optimization */\r
++          /* ignore notmuch, gnus special dirs (or such-named files) */\r
++          if (strcmp (entry->d_name, ".notmuch") == 0 ||\r
++              strcmp (entry->d_name, ".nnmaildir") == 0)\r
++              return 1;\r
++      }\r
++    }\r
++    \r
++    /* we also check if dir contains a file called '.noindex'; if so,\r
++     * we ignore this directory; alloca would be suitable here, if not\r
++     * for the portability. */\r
++    snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name);\r
++    if (access (noindex, F_OK) == 0)\r
++      return 1;\r
++    \r
++    return 0; /* don't ignore */\r
++}\r
++\r
++    \r
++\r
+ /* Examine 'path' recursively as follows:\r
+  *\r
+  *   o Ask the filesystem for the mtime of 'path' (path_mtime)\r
+@@ -181,21 +219,17 @@ add_files_recursive (notmuch_database_t *notmuch,\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
++      /* ignore tmp Maildirs, for obvious reasons */\r
++      if (entry->d_type == DT_DIR &&\r
++          (strcmp (entry->d_name, "tmp") == 0) &&\r
++          is_maildir (namelist, num_entries))\r
++          continue;\r
++      \r
++      /* ignore special directories and files */\r
++      if (ignore_dir_entry (path, entry))\r
++          continue;\r
++      \r
+       next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
\r
+       if (stat (next, st)) {\r
+@@ -394,18 +428,9 @@ count_files (const char *path, int *count)\r
\r
+         entry= namelist[i++];\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
+-          strcmp (entry->d_name, ".notmuch") == 0)\r
+-      {\r
++      if (ignore_dir_entry (path, entry))\r
+           continue;\r
+-      }\r
+-\r
++      \r
+       if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {\r
+           next = NULL;\r
+           fprintf (stderr, "Error descending from %s to %s: Out of memory\n",\r
+-- \r
+1.6.3.3\r
+\r