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 460FC431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 7 May 2012 14:08:39 -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 v9+Gi4YCfqE6 for <notmuch@notmuchmail.org>;
\r
16 Mon, 7 May 2012 14:08:37 -0700 (PDT)
\r
17 Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com
\r
18 [209.85.160.53]) (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 AF375431FAE
\r
21 for <notmuch@notmuchmail.org>; Mon, 7 May 2012 14:08:37 -0700 (PDT)
\r
22 Received: by pbbrr13 with SMTP id rr13so8240660pbb.26
\r
23 for <notmuch@notmuchmail.org>; Mon, 07 May 2012 14:08:35 -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=vmHcNGrU4I/7z3kpCwJhVirRk0Hap1yMXRTbQFRFyhE=;
\r
29 b=DPr1y4CbTOPTtEvpeHD99HPfPhoTveicyQjj6Bg4OkOBvUowBKdOQMBa02qjd4z07R
\r
30 R4mU/CesDgYezoLZgg9E5u0IEnC1GIqMX6b7L6mRzGLZrLtfyRixYs3F17RzlQtwoBNc
\r
31 1V1eH7WMdOGHDjJq6GJoIjoGSpJETl6eoac5umml1eiWdswcWZvNkpDdmSVlZUChb5Zo
\r
32 /3pcTk00NO0NoqJLfeIOVU7agItvYeJ87AgAbWJShTP+q/Brz643VLNre3gPcYFn23CS
\r
33 rQqdzTH8fh7L/w+pgMRfZHmSgPGfLc/2C+rRv3DvUCT4mSZirmGaq0zD2MbXaZMJOphx
\r
36 Received: by 10.68.236.5 with SMTP id uq5mr410171pbc.165.1336424915761; Mon,
\r
37 07 May 2012 14:08:35 -0700 (PDT)
\r
38 Received: by 10.68.52.33 with HTTP; Mon, 7 May 2012 14:08:35 -0700 (PDT)
\r
39 Received: by 10.68.52.33 with HTTP; Mon, 7 May 2012 14:08:35 -0700 (PDT)
\r
40 In-Reply-To: <1336414186-15293-3-git-send-email-amdragon@mit.edu>
\r
41 References: <1336414186-15293-1-git-send-email-amdragon@mit.edu>
\r
42 <1336414186-15293-3-git-send-email-amdragon@mit.edu>
\r
43 Date: Tue, 8 May 2012 00:08:35 +0300
\r
45 <CAB+hUn_rcz00p4kobjcf57aiyqSAWSPGgRSCNNG0b5eSye=3DQ@mail.gmail.com>
\r
46 Subject: Re: [PATCH 2/2] new: Centralize file type stat-ing logic
\r
47 From: Jani Nikula <jani@nikula.org>
\r
48 To: Austin Clements <amdragon@mit.edu>
\r
49 Content-Type: multipart/alternative; boundary=047d7b33c9c65f7b8204bf78ac10
\r
51 ALoCoQmhKRKJHFxNKNd4Q3OgSi6Wk0CGmXs1VXfUKMYwCjTunscnVZ4zVse3K3U19uflXQ4VgCwf
\r
52 Cc: Notmuch Mail <notmuch@notmuchmail.org>, Vladimir Marek <vlmarek@volny.cz>
\r
53 X-BeenThere: notmuch@notmuchmail.org
\r
54 X-Mailman-Version: 2.1.13
\r
56 List-Id: "Use and development of the notmuch mail system."
\r
57 <notmuch.notmuchmail.org>
\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
61 List-Post: <mailto:notmuch@notmuchmail.org>
\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
65 X-List-Received-Date: Mon, 07 May 2012 21:08:39 -0000
\r
67 --047d7b33c9c65f7b8204bf78ac10
\r
68 Content-Type: text/plain; charset=UTF-8
\r
70 On May 7, 2012 9:10 PM, "Austin Clements" <amdragon@mit.edu> wrote:
\r
72 > This moves our logic to get a file's type into one function. This has
\r
73 > several benefits: we can support OSes and file systems that do not
\r
74 > provide dirent.d_type or always return DT_UNKNOWN, complex
\r
75 > symlink-handling logic has been replaced by a simple stat fall-through
\r
76 > in one place, and the error message for un-stat-able file is more
\r
77 > accurate (previously, the error always mentioned directories, even
\r
78 > though a broken symlink is not a directory).
\r
80 Please find some quick drive-by-review below.
\r
85 > notmuch-new.c | 99
\r
86 ++++++++++++++++++++++++++++++++++-----------------------
\r
88 > 2 files changed, 60 insertions(+), 41 deletions(-)
\r
90 > diff --git a/notmuch-new.c b/notmuch-new.c
\r
91 > index cb720cc..cf2580e 100644
\r
92 > --- a/notmuch-new.c
\r
93 > +++ b/notmuch-new.c
\r
94 > @@ -154,6 +154,44 @@ dirent_sort_strcmp_name (const struct dirent **a,
\r
95 const struct dirent **b)
\r
96 > return strcmp ((*a)->d_name, (*b)->d_name);
\r
99 > +/* Return the type of a directory entry relative to path as a stat(2)
\r
100 > + * mode. Like stat, this follows symlinks. Returns -1 and sets errno
\r
101 > + * if the file's type cannot be determined (which includes dangling
\r
105 > +dirent_type (const char *path, const struct dirent *entry)
\r
107 > + struct stat statbuf;
\r
111 > +#ifdef _DIRENT_HAVE_D_TYPE
\r
112 > + /* Mapping from d_type to stat mode_t. We omit DT_LNK so that
\r
113 > + * we'll fall through to stat and get the real file type. */
\r
114 > + static const mode_t modes[] = {
\r
115 > + [DT_BLK] = S_IFBLK,
\r
116 > + [DT_CHR] = S_IFCHR,
\r
117 > + [DT_DIR] = S_IFDIR,
\r
118 > + [DT_FIFO] = S_IFIFO,
\r
119 > + [DT_REG] = S_IFREG,
\r
120 > + [DT_SOCK] = S_IFSOCK
\r
122 > + if (entry->d_type < sizeof(modes)/sizeof(modes[0]) &&
\r
126 > + modes[entry->d_type])
\r
127 > + return modes[entry->d_type];
\r
130 > + abspath = talloc_asprintf (NULL, "%s/%s", path, entry->d_name);
\r
134 Does talloc set errno in this case? I suspect not.
\r
136 > + err = stat(abspath, &statbuf);
\r
137 > + talloc_free (abspath);
\r
139 This likely breaks your promise about errno. You can't trust talloc_free()
\r
140 not calling some function that sets errno.
\r
144 > + return statbuf.st_mode & S_IFMT;
\r
147 > /* Test if the directory looks like a Maildir directory.
\r
149 > * Search through the array of directory entries to see if we can find all
\r
150 > @@ -162,12 +200,12 @@ dirent_sort_strcmp_name (const struct dirent **a,
\r
151 const struct dirent **b)
\r
152 > * Return 1 if the directory looks like a Maildir and 0 otherwise.
\r
155 > -_entries_resemble_maildir (struct dirent **entries, int count)
\r
156 > +_entries_resemble_maildir (const char *path, struct dirent **entries,
\r
159 > int i, found = 0;
\r
161 > for (i = 0; i < count; i++) {
\r
162 > - if (entries[i]->d_type != DT_DIR && entries[i]->d_type !=
\r
164 > + if (dirent_type (path, entries[i]) != S_IFDIR)
\r
167 > if (strcmp(entries[i]->d_name, "new") == 0 ||
\r
168 > @@ -250,7 +288,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
169 > notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
170 > notmuch_message_t *message = NULL;
\r
171 > struct dirent **fs_entries = NULL;
\r
172 > - int i, num_fs_entries;
\r
173 > + int i, num_fs_entries, entry_type;
\r
174 > notmuch_directory_t *directory;
\r
175 > notmuch_filenames_t *db_files = NULL;
\r
176 > notmuch_filenames_t *db_subdirs = NULL;
\r
177 > @@ -317,7 +355,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
180 > /* Pass 1: Recurse into all sub-directories. */
\r
181 > - is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
\r
182 > + is_maildir = _entries_resemble_maildir (path, fs_entries,
\r
185 > for (i = 0; i < num_fs_entries; i++) {
\r
187 > @@ -325,17 +363,16 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
189 > entry = fs_entries[i];
\r
191 > - /* We only want to descend into directories.
\r
192 > - * But symlinks can be to directories too, of course.
\r
194 > - * And if the filesystem doesn't tell us the file type in the
\r
195 > - * scandir results, then it might be a directory (and if not,
\r
196 > - * then we'll stat and return immediately in the next level of
\r
197 > - * recursion). */
\r
198 > - if (entry->d_type != DT_DIR &&
\r
199 > - entry->d_type != DT_LNK &&
\r
200 > - entry->d_type != DT_UNKNOWN)
\r
202 > + /* We only want to descend into directories (and symlinks to
\r
203 > + * directories). */
\r
204 > + entry_type = dirent_type (path, entry);
\r
205 > + if (entry_type == -1) {
\r
206 > + /* Be pessimistic, e.g. so we don't loose lots of mail
\r
210 > + * just because a user broke a symlink. */
\r
211 > + fprintf (stderr, "Error reading file %s/%s: %s\n",
\r
212 > + path, entry->d_name, strerror (errno));
\r
214 You can't trust errno here, as explained above.
\r
216 > + return NOTMUCH_STATUS_FILE_ERROR;
\r
217 > + } else if (entry_type != S_IFDIR) {
\r
221 > @@ -425,31 +462,13 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
222 > notmuch_filenames_move_to_next (db_subdirs);
\r
225 > - /* If we're looking at a symlink, we only want to add it if it
\r
226 > - * links to a regular file, (and not to a directory, say).
\r
228 > - * Similarly, if the file is of unknown type (due to filesystem
\r
229 > - * limitations), then we also need to look closer.
\r
231 > - * In either case, a stat does the trick.
\r
233 > - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
\r
236 > - next = talloc_asprintf (notmuch, "%s/%s", path,
\r
238 > - err = stat (next, &st);
\r
239 > - talloc_free (next);
\r
242 > - /* Don't emit an error for a link pointing nowhere, since
\r
243 > - * the directory-traversal pass will have already done
\r
248 > - if (! S_ISREG (st.st_mode))
\r
250 > - } else if (entry->d_type != DT_REG) {
\r
251 > + /* Only add regular files (and symlinks to regular files). */
\r
252 > + entry_type = dirent_type (path, entry);
\r
253 > + if (entry_type == -1) {
\r
254 > + fprintf (stderr, "Error reading file %s/%s: %s\n",
\r
255 > + path, entry->d_name, strerror (errno));
\r
259 > + return NOTMUCH_STATUS_FILE_ERROR;
\r
260 > + } else if (entry_type != S_IFREG) {
\r
264 > diff --git a/test/new b/test/new
\r
265 > index 26253db..e3900f5 100755
\r
268 > @@ -140,7 +140,7 @@ test_begin_subtest "Broken symlink aborts"
\r
269 > ln -s does-not-exist "${MAIL_DIR}/broken"
\r
270 > output=$(NOTMUCH_NEW 2>&1)
\r
271 > test_expect_equal "$output" \
\r
272 > -"Error reading directory /run/shm/nm/tmp.new/mail/broken: No such file
\r
274 > +"Error reading file /run/shm/nm/tmp.new/mail/broken: No such file or
\r
276 > Note: A fatal error was encountered: Something went wrong trying to read
\r
279 > rm "${MAIL_DIR}/broken"
\r
283 > _______________________________________________
\r
284 > notmuch mailing list
\r
285 > notmuch@notmuchmail.org
\r
286 > http://notmuchmail.org/mailman/listinfo/notmuch
\r
288 --047d7b33c9c65f7b8204bf78ac10
\r
289 Content-Type: text/html; charset=UTF-8
\r
290 Content-Transfer-Encoding: quoted-printable
\r
293 On May 7, 2012 9:10 PM, "Austin Clements" <<a href=3D"mailto:a=
\r
294 mdragon@mit.edu">amdragon@mit.edu</a>> wrote:<br>
\r
296 > This moves our logic to get a file's type into one function. =C2=
\r
298 > several benefits: we can support OSes and file systems that do not<br>
\r
299 > provide dirent.d_type or always return DT_UNKNOWN, complex<br>
\r
300 > symlink-handling logic has been replaced by a simple stat fall-through=
\r
302 > in one place, and the error message for un-stat-able file is more<br>
\r
303 > accurate (previously, the error always mentioned directories, even<br>
\r
304 > though a broken symlink is not a directory).</p>
\r
305 <p>Please find some quick drive-by-review below.</p>
\r
308 > =C2=A0notmuch-new.c | =C2=A0 99 ++++++++++++++++++++++++++++++++++----=
\r
309 -------------------<br>
\r
310 > =C2=A0test/new =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A02 +-<br>
\r
311 > =C2=A02 files changed, 60 insertions(+), 41 deletions(-)<br>
\r
313 > diff --git a/notmuch-new.c b/notmuch-new.c<br>
\r
314 > index cb720cc..cf2580e 100644<br>
\r
315 > --- a/notmuch-new.c<br>
\r
316 > +++ b/notmuch-new.c<br>
\r
317 > @@ -154,6 +154,44 @@ dirent_sort_strcmp_name (const struct dirent **a,=
\r
318 const struct dirent **b)<br>
\r
319 > =C2=A0 =C2=A0 return strcmp ((*a)->d_name, (*b)->d_name);<br>
\r
322 > +/* Return the type of a directory entry relative to path as a stat(2)=
\r
324 > + * mode. =C2=A0Like stat, this follows symlinks. =C2=A0Returns -1 and=
\r
326 > + * if the file's type cannot be determined (which includes dangli=
\r
328 > + * symlinks).<br>
\r
330 > +static int<br>
\r
331 > +dirent_type (const char *path, const struct dirent *entry)<br>
\r
333 > + =C2=A0 =C2=A0struct stat statbuf;<br>
\r
334 > + =C2=A0 =C2=A0char *abspath;<br>
\r
335 > + =C2=A0 =C2=A0int err;<br>
\r
337 > +#ifdef _DIRENT_HAVE_D_TYPE<br>
\r
338 > + =C2=A0 =C2=A0/* Mapping from d_type to stat mode_t. =C2=A0We omit DT=
\r
340 > + =C2=A0 =C2=A0 * we'll fall through to stat and get the real file=
\r
342 > + =C2=A0 =C2=A0static const mode_t modes[] =3D {<br>
\r
343 > + =C2=A0 =C2=A0 =C2=A0 [DT_BLK] =C2=A0=3D S_IFBLK,<br>
\r
344 > + =C2=A0 =C2=A0 =C2=A0 [DT_CHR] =C2=A0=3D S_IFCHR,<br>
\r
345 > + =C2=A0 =C2=A0 =C2=A0 [DT_DIR] =C2=A0=3D S_IFDIR,<br>
\r
346 > + =C2=A0 =C2=A0 =C2=A0 [DT_FIFO] =3D S_IFIFO,<br>
\r
347 > + =C2=A0 =C2=A0 =C2=A0 [DT_REG] =C2=A0=3D S_IFREG,<br>
\r
348 > + =C2=A0 =C2=A0 =C2=A0 [DT_SOCK] =3D S_IFSOCK<br>
\r
349 > + =C2=A0 =C2=A0};<br>
\r
350 > + =C2=A0 =C2=A0if (entry->d_type < sizeof(modes)/sizeof(modes[0]=
\r
352 <p>ARRAY_SIZE()</p>
\r
353 <p>> + =C2=A0 =C2=A0 =C2=A0 modes[entry->d_type])<br>
\r
354 > + =C2=A0 =C2=A0 =C2=A0 return modes[entry->d_type];<br>
\r
357 > + =C2=A0 =C2=A0abspath =3D talloc_asprintf (NULL, "%s/%s", p=
\r
358 ath, entry->d_name);<br>
\r
359 > + =C2=A0 =C2=A0if (!abspath)<br>
\r
360 > + =C2=A0 =C2=A0 =C2=A0 return -1;</p>
\r
361 <p>Does talloc set errno in this case? I suspect not.</p>
\r
362 <p>> + =C2=A0 =C2=A0err =3D stat(abspath, &statbuf);<br>
\r
363 > + =C2=A0 =C2=A0talloc_free (abspath);</p>
\r
364 <p>This likely breaks your promise about errno. You can't trust talloc_=
\r
365 free() not calling some function that sets errno.</p>
\r
366 <p>> + =C2=A0 =C2=A0if (err < 0)<br>
\r
367 > + =C2=A0 =C2=A0 =C2=A0 return -1;<br>
\r
368 > + =C2=A0 =C2=A0return statbuf.st_mode & S_IFMT;<br>
\r
371 > =C2=A0/* Test if the directory looks like a Maildir directory.<br>
\r
373 > =C2=A0* Search through the array of directory entries to see if we can=
\r
375 > @@ -162,12 +200,12 @@ dirent_sort_strcmp_name (const struct dirent **a=
\r
376 , const struct dirent **b)<br>
\r
377 > =C2=A0* Return 1 if the directory looks like a Maildir and 0 otherwise=
\r
380 > =C2=A0static int<br>
\r
381 > -_entries_resemble_maildir (struct dirent **entries, int count)<br>
\r
382 > +_entries_resemble_maildir (const char *path, struct dirent **entries,=
\r
385 > =C2=A0 =C2=A0 int i, found =3D 0;<br>
\r
387 > =C2=A0 =C2=A0 for (i =3D 0; i < count; i++) {<br>
\r
388 > - =C2=A0 =C2=A0 =C2=A0 if (entries[i]->d_type !=3D DT_DIR &&=
\r
389 ; entries[i]->d_type !=3D DT_UNKNOWN)<br>
\r
390 > + =C2=A0 =C2=A0 =C2=A0 if (dirent_type (path, entries[i]) !=3D S_IFDIR=
\r
392 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
394 > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (strcmp(entries[i]->d_name, "new=
\r
395 ") =3D=3D 0 ||<br>
\r
396 > @@ -250,7 +288,7 @@ add_files_recursive (notmuch_database_t *notmuch,<=
\r
398 > =C2=A0 =C2=A0 notmuch_status_t status, ret =3D NOTMUCH_STATUS_SUCCESS;=
\r
400 > =C2=A0 =C2=A0 notmuch_message_t *message =3D NULL;<br>
\r
401 > =C2=A0 =C2=A0 struct dirent **fs_entries =3D NULL;<br>
\r
402 > - =C2=A0 =C2=A0int i, num_fs_entries;<br>
\r
403 > + =C2=A0 =C2=A0int i, num_fs_entries, entry_type;<br>
\r
404 > =C2=A0 =C2=A0 notmuch_directory_t *directory;<br>
\r
405 > =C2=A0 =C2=A0 notmuch_filenames_t *db_files =3D NULL;<br>
\r
406 > =C2=A0 =C2=A0 notmuch_filenames_t *db_subdirs =3D NULL;<br>
\r
407 > @@ -317,7 +355,7 @@ add_files_recursive (notmuch_database_t *notmuch,<=
\r
409 > =C2=A0 =C2=A0 }<br>
\r
411 > =C2=A0 =C2=A0 /* Pass 1: Recurse into all sub-directories. */<br>
\r
412 > - =C2=A0 =C2=A0is_maildir =3D _entries_resemble_maildir (fs_entries, n=
\r
413 um_fs_entries);<br>
\r
414 > + =C2=A0 =C2=A0is_maildir =3D _entries_resemble_maildir (path, fs_entr=
\r
415 ies, num_fs_entries);<br>
\r
417 > =C2=A0 =C2=A0 for (i =3D 0; i < num_fs_entries; i++) {<br>
\r
418 > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (interrupted)<br>
\r
419 > @@ -325,17 +363,16 @@ add_files_recursive (notmuch_database_t *notmuch=
\r
422 > =C2=A0 =C2=A0 =C2=A0 =C2=A0entry =3D fs_entries[i];<br>
\r
424 > - =C2=A0 =C2=A0 =C2=A0 /* We only want to descend into directories.<br=
\r
426 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* But symlinks can be to directories too,=
\r
428 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
429 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* And if the filesystem doesn't tell =
\r
430 us the file type in the<br>
\r
431 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* scandir results, then it might be a dir=
\r
432 ectory (and if not,<br>
\r
433 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* then we'll stat and return immediat=
\r
434 ely in the next level of<br>
\r
435 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* recursion). */<br>
\r
436 > - =C2=A0 =C2=A0 =C2=A0 if (entry->d_type !=3D DT_DIR &&<br>
\r
437 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry->d_type !=3D DT_LNK &=
\r
439 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 entry->d_type !=3D DT_UNKNOWN)=
\r
441 > - =C2=A0 =C2=A0 =C2=A0 {<br>
\r
442 > + =C2=A0 =C2=A0 =C2=A0 /* We only want to descend into directories (an=
\r
444 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0* directories). */<br>
\r
445 > + =C2=A0 =C2=A0 =C2=A0 entry_type =3D dirent_type (path, entry);<br>
\r
446 > + =C2=A0 =C2=A0 =C2=A0 if (entry_type =3D=3D -1) {<br>
\r
447 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Be pessimistic, e.g. so we don=
\r
448 't loose lots of mail</p>
\r
449 <p>s/loose/lose/ ?</p>
\r
450 <p>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* just because a user br=
\r
451 oke a symlink. */<br>
\r
452 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Error read=
\r
453 ing file %s/%s: %s\n",<br>
\r
454 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
\r
455 =A0path, entry->d_name, strerror (errno));</p>
\r
456 <p>You can't trust errno here, as explained above.</p>
\r
457 <p>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NOTMUCH_STATUS_FILE_ERR=
\r
459 > + =C2=A0 =C2=A0 =C2=A0 } else if (entry_type !=3D S_IFDIR) {<br>
\r
460 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
461 > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
463 > @@ -425,31 +462,13 @@ add_files_recursive (notmuch_database_t *notmuch=
\r
465 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch_filenames_move_to_nex=
\r
466 t (db_subdirs);<br>
\r
467 > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
469 > - =C2=A0 =C2=A0 =C2=A0 /* If we're looking at a symlink, we only w=
\r
470 ant to add it if it<br>
\r
471 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* links to a regular file, (and not to a =
\r
472 directory, say).<br>
\r
473 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
474 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* Similarly, if the file is of unknown ty=
\r
475 pe (due to filesystem<br>
\r
476 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* limitations), then we also need to look=
\r
478 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*<br>
\r
479 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0* In either case, a stat does the trick.<=
\r
481 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0*/<br>
\r
482 > - =C2=A0 =C2=A0 =C2=A0 if (entry->d_type =3D=3D DT_LNK || entry->=
\r
483 ;d_type =3D=3D DT_UNKNOWN) {<br>
\r
484 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int err;<br>
\r
486 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 next =3D talloc_asprintf (notmuch=
\r
487 , "%s/%s", path, entry->d_name);<br>
\r
488 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 err =3D stat (next, &st);<br>
\r
489 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 talloc_free (next);<br>
\r
490 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 next =3D NULL;<br>
\r
492 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Don't emit an error for a =
\r
493 link pointing nowhere, since<br>
\r
494 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* the directory-traversal p=
\r
495 ass will have already done<br>
\r
496 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* that. */<br>
\r
497 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (err)<br>
\r
498 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>
\r
500 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (! S_ISREG (st.st_mode))<br>
\r
501 > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<br>
\r
502 > - =C2=A0 =C2=A0 =C2=A0 } else if (entry->d_type !=3D DT_REG) {<br>
\r
503 > + =C2=A0 =C2=A0 =C2=A0 /* Only add regular files (and symlinks to regu=
\r
505 > + =C2=A0 =C2=A0 =C2=A0 entry_type =3D dirent_type (path, entry);<br>
\r
506 > + =C2=A0 =C2=A0 =C2=A0 if (entry_type =3D=3D -1) {<br>
\r
507 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Error read=
\r
508 ing file %s/%s: %s\n",<br>
\r
509 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
\r
510 =A0path, entry->d_name, strerror (errno));</p>
\r
512 <p>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NOTMUCH_STATUS_FILE_ERR=
\r
514 > + =C2=A0 =C2=A0 =C2=A0 } else if (entry_type !=3D S_IFREG) {<br>
\r
515 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;<br>
\r
516 > =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
\r
518 > diff --git a/test/new b/test/new<br>
\r
519 > index 26253db..e3900f5 100755<br>
\r
520 > --- a/test/new<br>
\r
521 > +++ b/test/new<br>
\r
522 > @@ -140,7 +140,7 @@ test_begin_subtest "Broken symlink aborts&quo=
\r
524 > =C2=A0ln -s does-not-exist "${MAIL_DIR}/broken"<br>
\r
525 > =C2=A0output=3D$(NOTMUCH_NEW 2>&1)<br>
\r
526 > =C2=A0test_expect_equal "$output" \<br>
\r
527 > -"Error reading directory /run/shm/nm/tmp.new/mail/broken: No suc=
\r
528 h file or directory<br>
\r
529 > +"Error reading file /run/shm/nm/tmp.new/mail/broken: No such fil=
\r
531 > =C2=A0Note: A fatal error was encountered: Something went wrong trying=
\r
532 to read or write a file<br>
\r
533 > =C2=A0No new mail."<br>
\r
534 > =C2=A0rm "${MAIL_DIR}/broken"<br>
\r
538 > _______________________________________________<br>
\r
539 > notmuch mailing list<br>
\r
540 > <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=
\r
542 > <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=
\r
543 muchmail.org/mailman/listinfo/notmuch</a><br>
\r
546 --047d7b33c9c65f7b8204bf78ac10--
\r