1 Return-Path: <tomi.ollila@iki.fi>
\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 arlo.cworth.org (Postfix) with ESMTP id A91D26DE0350
\r
6 for <notmuch@notmuchmail.org>; Sun, 10 Apr 2016 23:44:56 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.62 tagged_above=-999 required=5 tests=[AWL=-0.032,
\r
12 SPF_NEUTRAL=0.652] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id GiHOHFxr9M74 for <notmuch@notmuchmail.org>;
\r
16 Sun, 10 Apr 2016 23:44:48 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id E4D186DE0317
\r
19 for <notmuch@notmuchmail.org>; Sun, 10 Apr 2016 23:44:47 -0700 (PDT)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 28E90100090;
\r
22 Mon, 11 Apr 2016 09:44:50 +0300 (EEST)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH 2/3] lib: fix handling of one character long directory
\r
27 In-Reply-To: <1460317403-13714-2-git-send-email-jani@nikula.org>
\r
28 References: <1460317403-13714-1-git-send-email-jani@nikula.org>
\r
29 <1460317403-13714-2-git-send-email-jani@nikula.org>
\r
30 User-Agent: Notmuch/0.21+99~g7cbc880 (http://notmuchmail.org) Emacs/24.3.1
\r
31 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Mon, 11 Apr 2016 09:44:49 +0300
\r
36 Message-ID: <m2d1pwzlsu.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.20
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Mon, 11 Apr 2016 06:44:56 -0000
\r
53 On Sun, Apr 10 2016, Jani Nikula <jani@nikula.org> wrote:
\r
55 > The code to skip multiple slashes in _notmuch_database_split_path()
\r
56 > skips back one character too much. This is compensated by a +1 in the
\r
57 > length parameter to the strndup() call. Mostly this works fine, but if
\r
58 > the path is to a file under a top level directory with one character
\r
59 > long name, the directory part is mistaken to be part of the file name
\r
60 > (slash == path in code). The returned directory name will be the empty
\r
61 > string and the basename will be the full path, breaking the indexing
\r
62 > logic in notmuch new.
\r
64 > Fix the multiple slash skipping to keep the slash variable pointing at
\r
65 > the last slash, and adjust strndup() accordingly.
\r
67 Good work. Changes look good. Tests pass...
\r
69 ... I also debugged this yesterday with an extra debug print:
\r
72 @@ -382,2 +382,3 @@ add_files (notmuch_database_t *notmuch,
\r
73 status = notmuch_database_get_directory (notmuch, path, &directory);
\r
74 + printf("(Z) %s %p %d\n", path, directory, status);
\r
77 Without these changes the %p printing directory value never changed from
\r
78 (nil) to ... non-nil with one-character directory names (meaning directory
\r
79 was found in database), after this patch the directory value worked like
\r
80 with longer directory names.
\r
85 > The bug was introduced in
\r
87 > commit e890b0cf4011fd9fd77ebd87343379e4a778888b
\r
88 > Author: Carl Worth <cworth@cworth.org>
\r
89 > Date: Sat Dec 19 13:20:26 2009 -0800
\r
91 > database: Store the parent ID for each directory document.
\r
93 > just a little over two months after the initial commit in the Notmuch
\r
94 > code history, making this the longest living bug in Notmuch to date.
\r
96 > lib/database.cc | 4 ++--
\r
97 > test/T050-new.sh | 5 -----
\r
98 > 2 files changed, 2 insertions(+), 7 deletions(-)
\r
100 > diff --git a/lib/database.cc b/lib/database.cc
\r
101 > index 3b342f136a53..b8486f7d5271 100644
\r
102 > --- a/lib/database.cc
\r
103 > +++ b/lib/database.cc
\r
104 > @@ -1781,7 +1781,7 @@ _notmuch_database_split_path (void *ctx,
\r
106 > /* Finally, skip multiple slashes. */
\r
107 > while (slash != path) {
\r
108 > - if (*slash != '/')
\r
109 > + if (*(slash - 1) != '/')
\r
113 > @@ -1794,7 +1794,7 @@ _notmuch_database_split_path (void *ctx,
\r
114 > *basename = path;
\r
117 > - *directory = talloc_strndup (ctx, path, slash - path + 1);
\r
118 > + *directory = talloc_strndup (ctx, path, slash - path);
\r
121 > return NOTMUCH_STATUS_SUCCESS;
\r
122 > diff --git a/test/T050-new.sh b/test/T050-new.sh
\r
123 > index 174715aa2781..53e02d22c383 100755
\r
124 > --- a/test/T050-new.sh
\r
125 > +++ b/test/T050-new.sh
\r
126 > @@ -170,7 +170,6 @@ test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory $
\r
127 > No new mail. Removed 3 messages."
\r
129 > test_begin_subtest "One character directory at top level"
\r
130 > -test_subtest_known_broken
\r
132 > generate_message [dir]=A
\r
133 > generate_message [dir]=A/B
\r
134 > @@ -179,10 +178,6 @@ generate_message [dir]=A/B/C
\r
135 > output=$(NOTMUCH_NEW --debug)
\r
136 > test_expect_equal "$output" "Added 3 new messages to the database."
\r
138 > -# clean up after the broken test to not mess up other tests
\r
139 > -rm -rf "${MAIL_DIR}"/A
\r
140 > -NOTMUCH_NEW 2>&1 > /dev/null
\r
142 > test_begin_subtest "Support single-message mbox"
\r
143 > cat > "${MAIL_DIR}"/mbox_file1 <<EOF
\r
144 > From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
\r
148 > _______________________________________________
\r
149 > notmuch mailing list
\r
150 > notmuch@notmuchmail.org
\r
151 > https://notmuchmail.org/mailman/listinfo/notmuch
\r