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 D95B0431FBC
\r
6 for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:50 -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 uvPPXZ2C0OkF for <notmuch@notmuchmail.org>;
\r
11 Sun, 10 Jan 2010 06:22:49 -0800 (PST)
\r
12 Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi
\r
14 by olra.theworths.org (Postfix) with ESMTP id 61FD1431FAE
\r
15 for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:49 -0800 (PST)
\r
16 Received: from djcbsoftware.nl (a88-114-93-212.elisa-laajakaista.fi
\r
18 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 060D42167BD
\r
21 for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:44 +0200 (EET)
\r
22 Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])
\r
23 by djcbsoftware.nl (Postfix) with ESMTP id 8D4FB39C598
\r
24 for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:20 +0200 (EET)
\r
25 Date: Sun, 10 Jan 2010 16:22:20 +0200
\r
26 Message-ID: <878wc69h0j.wl%djcb@djcbsoftware.nl>
\r
27 From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>
\r
28 To: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>
\r
29 Mail-Reply-To: djcb@djcbsoftware.nl
\r
30 User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0
\r
32 Organization: DJCBSoftware
\r
33 MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")
\r
34 Content-Type: text/plain; charset=US-ASCII
\r
35 Subject: [notmuch] [PATCH] * notmuch-new.c: refactor and improve
\r
36 dirs-to-ignore a bit
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 Reply-To: djcb@djcbsoftware.nl
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sun, 10 Jan 2010 14:22:51 -0000
\r
53 Below, an updated patch for the latest notmuch; this refractors the dir check
\r
54 a bit, and adds the useful feature of making 'notmuch new' ignore directories
\r
55 with a '.noindex'-file in them.
\r
61 [PATCH] * notmuch-new.c: refactor and improve dirs-to-ignore a bit
\r
63 add a new function ignore_dir_entry, which determines whether a dir entry
\r
64 should be ignored (not entered).
\r
66 dirs to ignore are: '.' and '..', '.notmuch' and 'nnmaildir' (the later from
\r
67 gnus). Also, ignore dirs that contain a file called '.noindex'; thus, we can
\r
68 tell not much not to consider e.g. dirs with spam messages.
\r
70 notmuch-new.c | 76 ++++++++++++++++++++++++++++++++++++++++++---------------
\r
71 1 files changed, 56 insertions(+), 20 deletions(-)
\r
73 diff --git a/notmuch-new.c b/notmuch-new.c
\r
74 index b740ee2..d1526cd 100644
\r
77 @@ -169,6 +169,47 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
82 +/* Ignore special directories to avoid infinite recursion.
\r
83 + * Also ignore the .notmuch directory and any "tmp" directory
\r
84 + * that appears within a maildir.
\r
87 +ignore_dir_entry (const char* path, struct dirent *entry)
\r
89 + char noindex[4096]; /* any path will fit */
\r
91 + /* ignore everything starting with a dot; this covers hidden
\r
92 + * files, as well as special dir (. and ..), but also things like
\r
93 + * gnus .nnmaildir or .notmuch */
\r
95 + /* special handling for dot-dirs */
\r
96 + if (entry->d_name[0] == '.') {
\r
98 + /* ignore '.' and '..' */
\r
99 + if (entry->d_name[1] == '\0' ||
\r
100 + (entry->d_name[1] == '.' && entry->d_name[2] == '\0'))
\r
103 + if (entry->d_name[1] == 'n') { /* optimization */
\r
104 + /* ignore notmuch, gnus special dirs (or such-named files) */
\r
105 + if (strcmp (entry->d_name, ".notmuch") == 0 ||
\r
106 + strcmp (entry->d_name, ".nnmaildir") == 0)
\r
111 + /* we also check if dir contains a file called '.noindex'; if so,
\r
112 + * we ignore this directory; alloca would be suitable here, if not
\r
113 + * for the portability. */
\r
114 + snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name);
\r
115 + if (access (noindex, F_OK) == 0)
\r
118 + return 0; /* don't ignore */
\r
122 /* Examine 'path' recursively as follows:
\r
124 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
125 @@ -275,21 +316,18 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
127 if (entry->d_type != DT_DIR && entry->d_type != DT_LNK)
\r
130 + /* ignore tmp Maildirs, for obvious reasons */
\r
131 + if (is_maildir && strcmp (entry->d_name, "tmp") == 0)
\r
134 /* Ignore special directories to avoid infinite recursion.
\r
135 - * Also ignore the .notmuch directory and any "tmp" directory
\r
136 - * that appears within a maildir.
\r
137 + * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and
\r
138 + * the .notmuch and .nnmaildir directories.
\r
140 - /* XXX: Eventually we'll want more sophistication to let the
\r
141 - * user specify files to be ignored. */
\r
142 - if (strcmp (entry->d_name, ".") == 0 ||
\r
143 - strcmp (entry->d_name, "..") == 0 ||
\r
144 - (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
145 - strcmp (entry->d_name, ".notmuch") ==0)
\r
147 + if (ignore_dir_entry (path, entry))
\r
152 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
153 status = add_files_recursive (notmuch, next, state);
\r
154 if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
155 @@ -575,18 +613,16 @@ count_files (const char *path, int *count)
\r
157 entry = fs_entries[i++];
\r
159 + /* Note: it seems we're missing the '_entries_resemble_maildir' check
\r
162 /* Ignore special directories to avoid infinite recursion.
\r
163 - * Also ignore the .notmuch directory.
\r
164 + * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and
\r
165 + * the .notmuch and .nnmaildir directories.
\r
167 - /* XXX: Eventually we'll want more sophistication to let the
\r
168 - * user specify files to be ignored. */
\r
169 - if (strcmp (entry->d_name, ".") == 0 ||
\r
170 - strcmp (entry->d_name, "..") == 0 ||
\r
171 - strcmp (entry->d_name, ".notmuch") == 0)
\r
173 + if (ignore_dir_entry (path, entry))
\r
178 if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
\r
180 fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
\r
185 Dirk-Jan C. Binnema Helsinki, Finland
\r
186 e:djcb@djcbsoftware.nl w:www.djcbsoftware.nl
\r
187 pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C
\r