Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 56 / 1dcad1ba07fddc18ff4c50fed8ae21422184af
1 Return-Path: <djcb@djcbsoftware.nl>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 03BAF431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 12 Dec 2009 08:46:10 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id TR2VLImoolbx for <notmuch@notmuchmail.org>;\r
11         Sat, 12 Dec 2009 08:46:08 -0800 (PST)\r
12 Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi\r
13         [195.197.172.115])\r
14         by olra.theworths.org (Postfix) with ESMTP id 99CB8431FAE\r
15         for <notmuch@notmuchmail.org>; Sat, 12 Dec 2009 08:46:08 -0800 (PST)\r
16 Received: from djcbsoftware.nl (a88-112-254-208.elisa-laajakaista.fi\r
17         [88.112.254.208])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by gw01.mail.saunalahti.fi (Postfix) with ESMTP id 4A48F1514B5;\r
21         Sat, 12 Dec 2009 18:46:05 +0200 (EET)\r
22 Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])\r
23         by djcbsoftware.nl (Postfix) with ESMTP id 502EB39C0D8;\r
24         Sat, 12 Dec 2009 18:46:03 +0200 (EET)\r
25 Date: Sat, 12 Dec 2009 18:45:49 +0200\r
26 Message-ID: <87my1ocf9e.wl%djcb@djcbsoftware.nl>\r
27 From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>\r
28 To: David Maus <maus.david@gmail.com>\r
29 In-Reply-To: <874onwfizh.wl%maus.david@gmail.com>\r
30 References: <87r5r0ctl3.wl%djcb@djcbsoftware.nl>\r
31         <874onwfizh.wl%maus.david@gmail.com>\r
32 Mail-Reply-To: djcb@djcbsoftware.nl\r
33 User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0\r
34         (HANACHIRUSATO)\r
35 Organization: DJCBSoftware\r
36 MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")\r
37 Content-Type: text/plain; charset=US-ASCII\r
38 Cc: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>\r
39 Subject: Re: [notmuch] Subject: [PATCH] update the check whether a dir\r
40         entry   should be ignored.\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.12\r
43 Precedence: list\r
44 Reply-To: djcb@djcbsoftware.nl\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Sat, 12 Dec 2009 16:46:10 -0000\r
55 \r
56 Hi David,\r
57 \r
58 >>>>> "DM" == David Maus <maus.david@gmail.com> writes:\r
59 \r
60     >> There is one maybe controversial change, namely that it ignores all\r
61     >> dot-dirs; this works fine for .notmuch and .nnmaildir (gnus), but maybe\r
62     >> there is some valid use case for having mail in dot-dirs. Maybe one of\r
63     >> the IMAP-servers does this? Not sure. Anyway, I can change that part.\r
64 \r
65     DM> Yes, ignore dot-dirs completely is not a good idea as the "." is a\r
66     DM> common separator for mailbox hierarchies on imap servers. Dovecot uses\r
67     DM> it by default, Courier too.\r
68 \r
69 Thanks. I was suspecting something like that. Attached, updated patch that\r
70 also updates the counting part.\r
71 \r
72 ---\r
73  notmuch-new.c |   75 ++++++++++++++++++++++++++++++++++++++-------------------\r
74  1 files changed, 50 insertions(+), 25 deletions(-)\r
75 \r
76 diff --git a/notmuch-new.c b/notmuch-new.c\r
77 index 9d20616..411e084 100644\r
78 --- a/notmuch-new.c\r
79 +++ b/notmuch-new.c\r
80 @@ -109,6 +109,44 @@ is_maildir (struct dirent **entries, int count)\r
81      return 0;\r
82  }\r
83  \r
84 +\r
85 +static int\r
86 +ignore_dir_entry (const char* path, struct dirent *entry)\r
87 +{\r
88 +    char noindex[4096]; /* any path will fit */\r
89 +    \r
90 +    /* ignore everything starting with a dot; this covers hidden\r
91 +    * files, as well as special dir (. and ..), but also things like\r
92 +    * gnus .nnmaildir or .notmuch */\r
93 +\r
94 +    /* special handling for dot-dirs */\r
95 +    if (entry->d_name[0] == '.') {\r
96 +\r
97 +       /* ignore '.' and '..' */\r
98 +       if (entry->d_name[1] == '\0' ||\r
99 +           (entry->d_name[1] == '.' && entry->d_name[2] == '\0')) \r
100 +           return 1;\r
101 +       \r
102 +       if (entry->d_name[1] == 'n')  { /* optimization */\r
103 +           /* ignore notmuch, gnus special dirs (or such-named files) */\r
104 +           if (strcmp (entry->d_name, ".notmuch") == 0 ||\r
105 +               strcmp (entry->d_name, ".nnmaildir") == 0)\r
106 +               return 1;\r
107 +       }\r
108 +    }\r
109 +    \r
110 +    /* we also check if dir contains a file called '.noindex'; if so,\r
111 +     * we ignore this directory; alloca would be suitable here, if not\r
112 +     * for the portability. */\r
113 +    snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name);\r
114 +    if (access (noindex, F_OK) == 0)\r
115 +       return 1;\r
116 +    \r
117 +    return 0; /* don't ignore */\r
118 +}\r
119 +\r
120 +    \r
121 +\r
122  /* Examine 'path' recursively as follows:\r
123   *\r
124   *   o Ask the filesystem for the mtime of 'path' (path_mtime)\r
125 @@ -181,21 +219,17 @@ add_files_recursive (notmuch_database_t *notmuch,\r
126         if (path_mtime <= path_dbtime && entry->d_type == DT_REG)\r
127             continue;\r
128  \r
129 -       /* Ignore special directories to avoid infinite recursion.\r
130 -        * Also ignore the .notmuch directory.\r
131 -        */\r
132 -       /* XXX: Eventually we'll want more sophistication to let the\r
133 -        * user specify files to be ignored. */\r
134 -       if (strcmp (entry->d_name, ".") == 0 ||\r
135 -           strcmp (entry->d_name, "..") == 0 ||\r
136 -           (entry->d_type == DT_DIR &&\r
137 -            (strcmp (entry->d_name, "tmp") == 0) &&\r
138 -            is_maildir (namelist, num_entries)) ||\r
139 -           strcmp (entry->d_name, ".notmuch") ==0)\r
140 -       {\r
141 -           continue;\r
142 -       }\r
143  \r
144 +       /* ignore tmp Maildirs, for obvious reasons */\r
145 +       if (entry->d_type == DT_DIR &&\r
146 +           (strcmp (entry->d_name, "tmp") == 0) &&\r
147 +           is_maildir (namelist, num_entries))\r
148 +           continue;\r
149 +       \r
150 +       /* ignore special directories and files */\r
151 +       if (ignore_dir_entry (path, entry))\r
152 +           continue;\r
153 +       \r
154         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
155  \r
156         if (stat (next, st)) {\r
157 @@ -394,18 +428,9 @@ count_files (const char *path, int *count)\r
158  \r
159          entry= namelist[i++];\r
160  \r
161 -       /* Ignore special directories to avoid infinite recursion.\r
162 -        * Also ignore the .notmuch directory.\r
163 -        */\r
164 -       /* XXX: Eventually we'll want more sophistication to let the\r
165 -        * user specify files to be ignored. */\r
166 -       if (strcmp (entry->d_name, ".") == 0 ||\r
167 -           strcmp (entry->d_name, "..") == 0 ||\r
168 -           strcmp (entry->d_name, ".notmuch") == 0)\r
169 -       {\r
170 +       if (ignore_dir_entry (path, entry))\r
171             continue;\r
172 -       }\r
173 -\r
174 +       \r
175         if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {\r
176             next = NULL;\r
177             fprintf (stderr, "Error descending from %s to %s: Out of memory\n",\r
178 -- \r
179 1.6.3.3\r
180 \r