1 Return-Path: <jani@nikula.org>
\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 041EC431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 7 May 2012 14:14:19 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5
\r
12 tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 97veg8Yqlq81 for <notmuch@notmuchmail.org>;
\r
16 Mon, 7 May 2012 14:14:17 -0700 (PDT)
\r
17 Received: from mail-pz0-f45.google.com (mail-pz0-f45.google.com
\r
18 [209.85.210.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 5297A431FAE
\r
21 for <notmuch@notmuchmail.org>; Mon, 7 May 2012 14:14:17 -0700 (PDT)
\r
22 Received: by dadv2 with SMTP id v2so1373526dad.18
\r
23 for <notmuch@notmuchmail.org>; Mon, 07 May 2012 14:14:16 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=mime-version:in-reply-to:references:date:message-id:subject:from:to
\r
27 :cc:content-type:x-gm-message-state;
\r
28 bh=1XJHml9Fai3ajFhy8njaKRybJ9bdn4wi71JTo2fkpHg=;
\r
29 b=mOYmGNPyWdZGVzSReOh3GMZmJndsYVkhoMrB1S9cG+Hra6QxwihmERdrYETMcZx9yR
\r
30 //BFaI/LgnRNktwIwjYP9uJ4mHnKlv6XChQP93ZtPACQtU6P285TnkF9iTa3b/5sn1Vg
\r
31 gXJXLM/aeohszPV7Is9G2PEI0S5jCZq/Tq7pjqPykI/2urUcLSuyZpVGiYPwFOiCVXor
\r
32 zPJackD7I/L/kSNHaMI40Hpf1uxzV1DW0QYRNVh9Bxi8bARWldpcysTCgx8Wni6c9FRK
\r
33 WFsDXetSlFNjOxyfHTREcueXbLW+ZOxiLGOdkbBDTMrrFchXdfrvjQsWe7DutSJUA7vc
\r
36 Received: by 10.68.236.5 with SMTP id uq5mr455946pbc.165.1336425256404; Mon,
\r
37 07 May 2012 14:14:16 -0700 (PDT)
\r
38 Received: by 10.68.52.33 with HTTP; Mon, 7 May 2012 14:14:16 -0700 (PDT)
\r
39 Received: by 10.68.52.33 with HTTP; Mon, 7 May 2012 14:14:16 -0700 (PDT)
\r
41 <CAB+hUn_rcz00p4kobjcf57aiyqSAWSPGgRSCNNG0b5eSye=3DQ@mail.gmail.com>
\r
42 References: <1336414186-15293-1-git-send-email-amdragon@mit.edu>
\r
43 <1336414186-15293-3-git-send-email-amdragon@mit.edu>
\r
44 <CAB+hUn_rcz00p4kobjcf57aiyqSAWSPGgRSCNNG0b5eSye=3DQ@mail.gmail.com>
\r
45 Date: Tue, 8 May 2012 00:14:16 +0300
\r
47 <CAB+hUn917qxCVDat64NWpc9r5+9g7yS3y4snkv_p8Oo6Vh7OyQ@mail.gmail.com>
\r
48 Subject: Re: [PATCH 2/2] new: Centralize file type stat-ing logic
\r
49 From: Jani Nikula <jani@nikula.org>
\r
50 To: Austin Clements <amdragon@mit.edu>
\r
51 Content-Type: multipart/alternative; boundary=047d7b33c9c6ad473d04bf78c08a
\r
53 ALoCoQko9LcsJsIgWSM/hFYSIQSv26f8OUh8J4IapJWfjPERaQjv4mx9V6NmvBdVtDh3XV80rQPa
\r
54 Cc: Notmuch Mail <notmuch@notmuchmail.org>, Vladimir Marek <vlmarek@volny.cz>
\r
55 X-BeenThere: notmuch@notmuchmail.org
\r
56 X-Mailman-Version: 2.1.13
\r
58 List-Id: "Use and development of the notmuch mail system."
\r
59 <notmuch.notmuchmail.org>
\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
63 List-Post: <mailto:notmuch@notmuchmail.org>
\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
67 X-List-Received-Date: Mon, 07 May 2012 21:14:19 -0000
\r
69 --047d7b33c9c6ad473d04bf78c08a
\r
70 Content-Type: text/plain; charset=UTF-8
\r
72 On May 8, 2012 12:08 AM, "Jani Nikula" <jani@nikula.org> wrote:
\r
75 > On May 7, 2012 9:10 PM, "Austin Clements" <amdragon@mit.edu> wrote:
\r
77 > > This moves our logic to get a file's type into one function. This has
\r
78 > > several benefits: we can support OSes and file systems that do not
\r
79 > > provide dirent.d_type or always return DT_UNKNOWN, complex
\r
80 > > symlink-handling logic has been replaced by a simple stat fall-through
\r
81 > > in one place, and the error message for un-stat-able file is more
\r
82 > > accurate (previously, the error always mentioned directories, even
\r
83 > > though a broken symlink is not a directory).
\r
85 > Please find some quick drive-by-review below.
\r
87 Forgot to add that the general approach seems sensible to me.
\r
93 > > notmuch-new.c | 99
\r
94 ++++++++++++++++++++++++++++++++++-----------------------
\r
96 > > 2 files changed, 60 insertions(+), 41 deletions(-)
\r
98 > > diff --git a/notmuch-new.c b/notmuch-new.c
\r
99 > > index cb720cc..cf2580e 100644
\r
100 > > --- a/notmuch-new.c
\r
101 > > +++ b/notmuch-new.c
\r
102 > > @@ -154,6 +154,44 @@ dirent_sort_strcmp_name (const struct dirent **a,
\r
103 const struct dirent **b)
\r
104 > > return strcmp ((*a)->d_name, (*b)->d_name);
\r
107 > > +/* Return the type of a directory entry relative to path as a stat(2)
\r
108 > > + * mode. Like stat, this follows symlinks. Returns -1 and sets errno
\r
109 > > + * if the file's type cannot be determined (which includes dangling
\r
113 > > +dirent_type (const char *path, const struct dirent *entry)
\r
115 > > + struct stat statbuf;
\r
116 > > + char *abspath;
\r
119 > > +#ifdef _DIRENT_HAVE_D_TYPE
\r
120 > > + /* Mapping from d_type to stat mode_t. We omit DT_LNK so that
\r
121 > > + * we'll fall through to stat and get the real file type. */
\r
122 > > + static const mode_t modes[] = {
\r
123 > > + [DT_BLK] = S_IFBLK,
\r
124 > > + [DT_CHR] = S_IFCHR,
\r
125 > > + [DT_DIR] = S_IFDIR,
\r
126 > > + [DT_FIFO] = S_IFIFO,
\r
127 > > + [DT_REG] = S_IFREG,
\r
128 > > + [DT_SOCK] = S_IFSOCK
\r
130 > > + if (entry->d_type < sizeof(modes)/sizeof(modes[0]) &&
\r
134 > > + modes[entry->d_type])
\r
135 > > + return modes[entry->d_type];
\r
138 > > + abspath = talloc_asprintf (NULL, "%s/%s", path, entry->d_name);
\r
139 > > + if (!abspath)
\r
142 > Does talloc set errno in this case? I suspect not.
\r
144 > > + err = stat(abspath, &statbuf);
\r
145 > > + talloc_free (abspath);
\r
147 > This likely breaks your promise about errno. You can't trust
\r
148 talloc_free() not calling some function that sets errno.
\r
152 > > + return statbuf.st_mode & S_IFMT;
\r
155 > > /* Test if the directory looks like a Maildir directory.
\r
157 > > * Search through the array of directory entries to see if we can find
\r
159 > > @@ -162,12 +200,12 @@ dirent_sort_strcmp_name (const struct dirent **a,
\r
160 const struct dirent **b)
\r
161 > > * Return 1 if the directory looks like a Maildir and 0 otherwise.
\r
164 > > -_entries_resemble_maildir (struct dirent **entries, int count)
\r
165 > > +_entries_resemble_maildir (const char *path, struct dirent **entries,
\r
168 > > int i, found = 0;
\r
170 > > for (i = 0; i < count; i++) {
\r
171 > > - if (entries[i]->d_type != DT_DIR && entries[i]->d_type !=
\r
173 > > + if (dirent_type (path, entries[i]) != S_IFDIR)
\r
176 > > if (strcmp(entries[i]->d_name, "new") == 0 ||
\r
177 > > @@ -250,7 +288,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
178 > > notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
179 > > notmuch_message_t *message = NULL;
\r
180 > > struct dirent **fs_entries = NULL;
\r
181 > > - int i, num_fs_entries;
\r
182 > > + int i, num_fs_entries, entry_type;
\r
183 > > notmuch_directory_t *directory;
\r
184 > > notmuch_filenames_t *db_files = NULL;
\r
185 > > notmuch_filenames_t *db_subdirs = NULL;
\r
186 > > @@ -317,7 +355,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
189 > > /* Pass 1: Recurse into all sub-directories. */
\r
190 > > - is_maildir = _entries_resemble_maildir (fs_entries,
\r
192 > > + is_maildir = _entries_resemble_maildir (path, fs_entries,
\r
195 > > for (i = 0; i < num_fs_entries; i++) {
\r
196 > > if (interrupted)
\r
197 > > @@ -325,17 +363,16 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
199 > > entry = fs_entries[i];
\r
201 > > - /* We only want to descend into directories.
\r
202 > > - * But symlinks can be to directories too, of course.
\r
204 > > - * And if the filesystem doesn't tell us the file type in the
\r
205 > > - * scandir results, then it might be a directory (and if not,
\r
206 > > - * then we'll stat and return immediately in the next level of
\r
207 > > - * recursion). */
\r
208 > > - if (entry->d_type != DT_DIR &&
\r
209 > > - entry->d_type != DT_LNK &&
\r
210 > > - entry->d_type != DT_UNKNOWN)
\r
212 > > + /* We only want to descend into directories (and symlinks to
\r
213 > > + * directories). */
\r
214 > > + entry_type = dirent_type (path, entry);
\r
215 > > + if (entry_type == -1) {
\r
216 > > + /* Be pessimistic, e.g. so we don't loose lots of mail
\r
220 > > + * just because a user broke a symlink. */
\r
221 > > + fprintf (stderr, "Error reading file %s/%s: %s\n",
\r
222 > > + path, entry->d_name, strerror (errno));
\r
224 > You can't trust errno here, as explained above.
\r
226 > > + return NOTMUCH_STATUS_FILE_ERROR;
\r
227 > > + } else if (entry_type != S_IFDIR) {
\r
231 > > @@ -425,31 +462,13 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
232 > > notmuch_filenames_move_to_next (db_subdirs);
\r
235 > > - /* If we're looking at a symlink, we only want to add it if it
\r
236 > > - * links to a regular file, (and not to a directory, say).
\r
238 > > - * Similarly, if the file is of unknown type (due to filesystem
\r
239 > > - * limitations), then we also need to look closer.
\r
241 > > - * In either case, a stat does the trick.
\r
243 > > - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
\r
246 > > - next = talloc_asprintf (notmuch, "%s/%s", path,
\r
248 > > - err = stat (next, &st);
\r
249 > > - talloc_free (next);
\r
252 > > - /* Don't emit an error for a link pointing nowhere, since
\r
253 > > - * the directory-traversal pass will have already done
\r
258 > > - if (! S_ISREG (st.st_mode))
\r
260 > > - } else if (entry->d_type != DT_REG) {
\r
261 > > + /* Only add regular files (and symlinks to regular files). */
\r
262 > > + entry_type = dirent_type (path, entry);
\r
263 > > + if (entry_type == -1) {
\r
264 > > + fprintf (stderr, "Error reading file %s/%s: %s\n",
\r
265 > > + path, entry->d_name, strerror (errno));
\r
269 > > + return NOTMUCH_STATUS_FILE_ERROR;
\r
270 > > + } else if (entry_type != S_IFREG) {
\r
274 > > diff --git a/test/new b/test/new
\r
275 > > index 26253db..e3900f5 100755
\r
278 > > @@ -140,7 +140,7 @@ test_begin_subtest "Broken symlink aborts"
\r
279 > > ln -s does-not-exist "${MAIL_DIR}/broken"
\r
280 > > output=$(NOTMUCH_NEW 2>&1)
\r
281 > > test_expect_equal "$output" \
\r
282 > > -"Error reading directory /run/shm/nm/tmp.new/mail/broken: No such file
\r
284 > > +"Error reading file /run/shm/nm/tmp.new/mail/broken: No such file or
\r
286 > > Note: A fatal error was encountered: Something went wrong trying to
\r
287 read or write a file
\r
289 > > rm "${MAIL_DIR}/broken"
\r
293 > > _______________________________________________
\r
294 > > notmuch mailing list
\r
295 > > notmuch@notmuchmail.org
\r
296 > > http://notmuchmail.org/mailman/listinfo/notmuch
\r
298 --047d7b33c9c6ad473d04bf78c08a
\r
299 Content-Type: text/html; charset=UTF-8
\r
300 Content-Transfer-Encoding: quoted-printable
\r
303 On May 8, 2012 12:08 AM, "Jani Nikula" <<a href=3D"mailto:jani=
\r
304 @nikula.org">jani@nikula.org</a>> wrote:<br>
\r
307 > On May 7, 2012 9:10 PM, "Austin Clements" <<a href=3D"mai=
\r
308 lto:amdragon@mit.edu">amdragon@mit.edu</a>> wrote:<br>
\r
310 > > This moves our logic to get a file's type into one function. =
\r
312 > > several benefits: we can support OSes and file systems that do no=
\r
314 > > provide dirent.d_type or always return DT_UNKNOWN, complex<br>
\r
315 > > symlink-handling logic has been replaced by a simple stat fall-th=
\r
317 > > in one place, and the error message for un-stat-able file is more=
\r
319 > > accurate (previously, the error always mentioned directories, eve=
\r
321 > > though a broken symlink is not a directory).<br>
\r
323 > Please find some quick drive-by-review below.</p>
\r
324 <p>Forgot to add that the general approach seems sensible to me.<br></p>
\r
329 > > =C2=A0notmuch-new.c | =C2=A0 99 +++++++++++++++++++++++++++++++++=
\r
330 +-----------------------<br>
\r
331 > > =C2=A0test/new =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A02 +-<br>
\r
332 > > =C2=A02 files changed, 60 insertions(+), 41 deletions(-)<br>
\r
334 > > diff --git a/notmuch-new.c b/notmuch-new.c<br>
\r
335 > > index cb720cc..cf2580e 100644<br>
\r
336 > > --- a/notmuch-new.c<br>
\r
337 > > +++ b/notmuch-new.c<br>
\r
338 > > @@ -154,6 +154,44 @@ dirent_sort_strcmp_name (const struct dirent=
\r
339 **a, const struct dirent **b)<br>
\r
340 > > =C2=A0 =C2=A0 return strcmp ((*a)->d_name, (*b)->d_name);<b=
\r
342 > > =C2=A0}<br>
\r
344 > > +/* Return the type of a directory entry relative to path as a st=
\r
346 > > + * mode. =C2=A0Like stat, this follows symlinks. =C2=A0Returns -=
\r
347 1 and sets errno<br>
\r
348 > > + * if the file's type cannot be determined (which includes d=
\r
350 > > + * symlinks).<br>
\r
352 > > +static int<br>
\r
353 > > +dirent_type (const char *path, const struct dirent *entry)<br>
\r
355 > > + =C2=A0 =C2=A0struct stat statbuf;<br>
\r
356 > > + =C2=A0 =C2=A0char *abspath;<br>
\r
357 > > + =C2=A0 =C2=A0int err;<br>
\r
359 > > +#ifdef _DIRENT_HAVE_D_TYPE<br>
\r
360 > > + =C2=A0 =C2=A0/* Mapping from d_type to stat mode_t. =C2=A0We om=
\r
361 it DT_LNK so that<br>
\r
362 > > + =C2=A0 =C2=A0 * we'll fall through to stat and get the real=
\r
364 > > + =C2=A0 =C2=A0static const mode_t modes[] =3D {<br>
\r
365 > > + =C2=A0 =C2=A0 =C2=A0 [DT_BLK] =C2=A0=3D S_IFBLK,<br>
\r
366 > > + =C2=A0 =C2=A0 =C2=A0 [DT_CHR] =C2=A0=3D S_IFCHR,<br>
\r
367 > > + =C2=A0 =C2=A0 =C2=A0 [DT_DIR] =C2=A0=3D S_IFDIR,<br>
\r
368 > > + =C2=A0 =C2=A0 =C2=A0 [DT_FIFO] =3D S_IFIFO,<br>
\r
369 > > + =C2=A0 =C2=A0 =C2=A0 [DT_REG] =C2=A0=3D S_IFREG,<br>
\r
370 > > + =C2=A0 =C2=A0 =C2=A0 [DT_SOCK] =3D S_IFSOCK<br>
\r
371 > > + =C2=A0 =C2=A0};<br>
\r
372 > > + =C2=A0 =C2=A0if (entry->d_type < sizeof(modes)/sizeof(mod=
\r
373 es[0]) &&<br>
\r
375 > ARRAY_SIZE()<br>
\r
377 > > + =C2=A0 =C2=A0 =C2=A0 modes[entry->d_type])<br>
\r
378 > > + =C2=A0 =C2=A0 =C2=A0 return modes[entry->d_type];<br>
\r
379 > > +#endif<br>
\r
381 > > + =C2=A0 =C2=A0abspath =3D talloc_asprintf (NULL, "%s/%s&quo=
\r
382 t;, path, entry->d_name);<br>
\r
383 > > + =C2=A0 =C2=A0if (!abspath)<br>
\r
384 > > + =C2=A0 =C2=A0 =C2=A0 return -1;<br>
\r
386 > Does talloc set errno in this case? I suspect not.<br>
\r
388 > > + =C2=A0 =C2=A0err =3D stat(abspath, &statbuf);<br>
\r
389 > > + =C2=A0 =C2=A0talloc_free (abspath);<br>
\r
391 > This likely breaks your promise about errno. You can't trust tallo=
\r
392 c_free() not calling some function that sets errno.<br>
\r
394 > > + =C2=A0 =C2=A0if (err < 0)<br>
\r
395 > > + =C2=A0 =C2=A0 =C2=A0 return -1;<br>
\r
396 > > + =C2=A0 =C2=A0return statbuf.st_mode & S_IFMT;<br>
\r
399 > > =C2=A0/* Test if the directory looks like a Maildir directory.<br=
\r
401 > > =C2=A0*<br>
\r
402 > > =C2=A0* Search through the array of directory entries to see if w=
\r
404 > > @@ -162,12 +200,12 @@ dirent_sort_strcmp_name (const struct diren=
\r
405 t **a, const struct dirent **b)<br>
\r
406 > > =C2=A0* Return 1 if the directory looks like a Maildir and 0 othe=
\r
408 > > =C2=A0*/<br>
\r
409 > > =C2=A0static int<br>
\r
410 > > -_entries_resemble_maildir (struct dirent **entries, int count)<b=
\r
412 > > +_entries_resemble_maildir (const char *path, struct dirent **ent=
\r
413 ries, int count)<br>
\r
414 > > =C2=A0{<br>
\r
415 > > =C2=A0 =C2=A0 int i, found =3D 0;<br>
\r
417 > > =C2=A0 =C2=A0 for (i =3D 0; i < count; i++) {<br>
\r
418 > > - =C2=A0 =C2=A0 =C2=A0 if (entries[i]->d_type !=3D DT_DIR &=
\r
419 ;& entries[i]->d_type !=3D DT_UNKNOWN)<br>
\r
420 > > + =C2=A0 =C2=A0 =C2=A0 if (dirent_type (path, entries[i]) !=3D S_=
\r
422 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
424 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (strcmp(entries[i]->d_name, &quo=
\r
425 t;new") =3D=3D 0 ||<br>
\r
426 > > @@ -250,7 +288,7 @@ add_files_recursive (notmuch_database_t *notm=
\r
428 > > =C2=A0 =C2=A0 notmuch_status_t status, ret =3D NOTMUCH_STATUS_SUC=
\r
430 > > =C2=A0 =C2=A0 notmuch_message_t *message =3D NULL;<br>
\r
431 > > =C2=A0 =C2=A0 struct dirent **fs_entries =3D NULL;<br>
\r
432 > > - =C2=A0 =C2=A0int i, num_fs_entries;<br>
\r
433 > > + =C2=A0 =C2=A0int i, num_fs_entries, entry_type;<br>
\r
434 > > =C2=A0 =C2=A0 notmuch_directory_t *directory;<br>
\r
435 > > =C2=A0 =C2=A0 notmuch_filenames_t *db_files =3D NULL;<br>
\r
436 > > =C2=A0 =C2=A0 notmuch_filenames_t *db_subdirs =3D NULL;<br>
\r
437 > > @@ -317,7 +355,7 @@ add_files_recursive (notmuch_database_t *notm=
\r
439 > > =C2=A0 =C2=A0 }<br>
\r
441 > > =C2=A0 =C2=A0 /* Pass 1: Recurse into all sub-directories. */<br>
\r
442 > > - =C2=A0 =C2=A0is_maildir =3D _entries_resemble_maildir (fs_entri=
\r
443 es, num_fs_entries);<br>
\r
444 > > + =C2=A0 =C2=A0is_maildir =3D _entries_resemble_maildir (path, fs=
\r
445 _entries, num_fs_entries);<br>
\r
447 > > =C2=A0 =C2=A0 for (i =3D 0; i < num_fs_entries; i++) {<br>
\r
448 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (interrupted)<br>
\r
449 > > @@ -325,17 +363,16 @@ add_files_recursive (notmuch_database_t *no=
\r
452 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0entry =3D fs_entries[i];<br>
\r
454 > > - =C2=A0 =C2=A0 =C2=A0 /* We only want to descend into directorie=
\r
456 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* But symlinks can be to directories=
\r
457 too, of course.<br>
\r
458 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
459 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* And if the filesystem doesn't =
\r
460 tell us the file type in the<br>
\r
461 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* scandir results, then it might be =
\r
462 a directory (and if not,<br>
\r
463 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* then we'll stat and return imm=
\r
464 ediately in the next level of<br>
\r
465 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* recursion). */<br>
\r
466 > > - =C2=A0 =C2=A0 =C2=A0 if (entry->d_type !=3D DT_DIR &&=
\r
468 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry->d_type !=3D DT_LNK=
\r
470 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry->d_type !=3D DT_UNK=
\r
472 > > - =C2=A0 =C2=A0 =C2=A0 {<br>
\r
473 > > + =C2=A0 =C2=A0 =C2=A0 /* We only want to descend into directorie=
\r
474 s (and symlinks to<br>
\r
475 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0* directories). */<br>
\r
476 > > + =C2=A0 =C2=A0 =C2=A0 entry_type =3D dirent_type (path, entry);<=
\r
478 > > + =C2=A0 =C2=A0 =C2=A0 if (entry_type =3D=3D -1) {<br>
\r
479 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Be pessimistic, e.g. so w=
\r
480 e don't loose lots of mail<br>
\r
482 > s/loose/lose/ ?<br>
\r
484 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* just because a user =
\r
485 broke a symlink. */<br>
\r
486 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Error=
\r
487 reading file %s/%s: %s\n",<br>
\r
488 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
489 =C2=A0path, entry->d_name, strerror (errno));<br>
\r
491 > You can't trust errno here, as explained above.<br>
\r
493 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NOTMUCH_STATUS_FILE_E=
\r
495 > > + =C2=A0 =C2=A0 =C2=A0 } else if (entry_type !=3D S_IFDIR) {<br>
\r
496 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
497 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
499 > > @@ -425,31 +462,13 @@ add_files_recursive (notmuch_database_t *no=
\r
501 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch_filenames_move_t=
\r
502 o_next (db_subdirs);<br>
\r
503 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
505 > > - =C2=A0 =C2=A0 =C2=A0 /* If we're looking at a symlink, we o=
\r
506 nly want to add it if it<br>
\r
507 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* links to a regular file, (and not =
\r
508 to a directory, say).<br>
\r
509 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
510 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* Similarly, if the file is of unkno=
\r
511 wn type (due to filesystem<br>
\r
512 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* limitations), then we also need to=
\r
514 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
515 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* In either case, a stat does the tr=
\r
517 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*/<br>
\r
518 > > - =C2=A0 =C2=A0 =C2=A0 if (entry->d_type =3D=3D DT_LNK || entr=
\r
519 y->d_type =3D=3D DT_UNKNOWN) {<br>
\r
520 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int err;<br>
\r
522 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 next =3D talloc_asprintf (no=
\r
523 tmuch, "%s/%s", path, entry->d_name);<br>
\r
524 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 err =3D stat (next, &st)=
\r
526 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 talloc_free (next);<br>
\r
527 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 next =3D NULL;<br>
\r
529 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Don't emit an error f=
\r
530 or a link pointing nowhere, since<br>
\r
531 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* the directory-traver=
\r
532 sal pass will have already done<br>
\r
533 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* that. */<br>
\r
534 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (err)<br>
\r
535 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>
\r
537 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (! S_ISREG (st.st_mode))<=
\r
539 > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>
\r
540 > > - =C2=A0 =C2=A0 =C2=A0 } else if (entry->d_type !=3D DT_REG) {=
\r
542 > > + =C2=A0 =C2=A0 =C2=A0 /* Only add regular files (and symlinks to=
\r
543 regular files). */<br>
\r
544 > > + =C2=A0 =C2=A0 =C2=A0 entry_type =3D dirent_type (path, entry);<=
\r
546 > > + =C2=A0 =C2=A0 =C2=A0 if (entry_type =3D=3D -1) {<br>
\r
547 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Error=
\r
548 reading file %s/%s: %s\n",<br>
\r
549 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
550 =C2=A0path, entry->d_name, strerror (errno));<br>
\r
554 > > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NOTMUCH_STATUS_FILE_E=
\r
556 > > + =C2=A0 =C2=A0 =C2=A0 } else if (entry_type !=3D S_IFREG) {<br>
\r
557 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
558 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
560 > > diff --git a/test/new b/test/new<br>
\r
561 > > index 26253db..e3900f5 100755<br>
\r
562 > > --- a/test/new<br>
\r
563 > > +++ b/test/new<br>
\r
564 > > @@ -140,7 +140,7 @@ test_begin_subtest "Broken symlink abort=
\r
566 > > =C2=A0ln -s does-not-exist "${MAIL_DIR}/broken"<br>
\r
567 > > =C2=A0output=3D$(NOTMUCH_NEW 2>&1)<br>
\r
568 > > =C2=A0test_expect_equal "$output" \<br>
\r
569 > > -"Error reading directory /run/shm/nm/tmp.new/mail/broken: N=
\r
570 o such file or directory<br>
\r
571 > > +"Error reading file /run/shm/nm/tmp.new/mail/broken: No suc=
\r
572 h file or directory<br>
\r
573 > > =C2=A0Note: A fatal error was encountered: Something went wrong t=
\r
574 rying to read or write a file<br>
\r
575 > > =C2=A0No new mail."<br>
\r
576 > > =C2=A0rm "${MAIL_DIR}/broken"<br>
\r
578 > > 1.7.10<br>
\r
580 > > _______________________________________________<br>
\r
581 > > notmuch mailing list<br>
\r
582 > > <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.or=
\r
584 > > <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http:=
\r
585 //notmuchmail.org/mailman/listinfo/notmuch</a><br>
\r
588 --047d7b33c9c6ad473d04bf78c08a--
\r