[PATCH 5/9] new: Remove workaround for detecting newly created directory objects
[notmuch-archives.git] / b5 / 39c817101dedc059ba81767cf48fde413f47cd
1 Return-Path: <amdragon@mit.edu>\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 1D91B429E36\r
6         for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:14:00 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[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 i0e7ZYrcKgjs for <notmuch@notmuchmail.org>;\r
16         Thu, 17 May 2012 21:13:58 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 7729A429E25\r
20         for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:13:53 -0700 (PDT)\r
21 X-AuditID: 1209190f-b7f4f6d00000092b-3f-4fb5cc8052dc\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 38.3A.02347.08CC5BF4; Fri, 18 May 2012 00:13:52 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q4I4DqQN029944; \r
27         Fri, 18 May 2012 00:13:52 -0400\r
28 Received: from drake.mit.edu\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4I4DoPQ026788\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Fri, 18 May 2012 00:13:51 -0400 (EDT)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1SVEZa-0000z9-Io; Fri, 18 May 2012 00:13:50 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 5/9] new: Remove workaround for detecting newly created\r
41         directory objects\r
42 Date: Fri, 18 May 2012 00:13:38 -0400\r
43 Message-Id: <1337314423-3702-6-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1337314423-3702-1-git-send-email-amdragon@mit.edu>\r
46 References: <1337314423-3702-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrNtwZqu/weFvphbXb85kdmD0eLbq\r
49         FnMAYxSXTUpqTmZZapG+XQJXxrMvzcwFp6QrJj08wtrAOFu0i5GTQ0LARGLruSssELaYxIV7\r
50         69m6GLk4hAT2MUqcbP3PCOFsYJRomjmZGcK5zySxdP0zFghnFqPEwpd9TCD9bAIaEtv2L2cE\r
51         sUUEpCV23p3N2sXIwcEsoCbxp0sFJCwsEClx89csZhCbRUBVovPVTVYQm1fAXuL/pmtQZ8hL\r
52         PL3fxwbSyingIDHteDRIWAio5N+FZpYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Zro\r
53         5WaW6KWmlG5iBAeNJP8Oxm8HlQ4xCnAwKvHw7piz1V+INbGsuDL3EKMkB5OSKO/3k0AhvqT8\r
54         lMqMxOKM+KLSnNTiQ4wSHMxKIryy3UA53pTEyqrUonyYlDQHi5I4r5rWOz8hgfTEktTs1NSC\r
55         1CKYrAwHh5IEr8VpoEbBotT01Iq0zJwShDQTByfIcB6g4VogNbzFBYm5xZnpEPlTjIpS4rw2\r
56         IAkBkERGaR5cLyyqXzGKA70izBsKUsUDTAhw3a+ABjMBDS7L3QQyuCQRISXVwNiqb80Q17g1\r
57         Zf3xqetm/Qtgn9wx1UdDrDhi2d39Ktue6oT+nNruM+Pa7xmHvs0KSHado/f02iTThWGi8zYl\r
58         uW0/cue608cnUc83TpueaL/0xOlkw/KVvns8FdPeNopLalx7YLZp85z9W+avm/2698jb789W\r
59         LMy5GL9QWFjlYcqrfZ8e3rjc3X7gmhJLcUaioRZzUXEiACrcEnbFAgAA\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Fri, 18 May 2012 04:14:00 -0000\r
73 \r
74 Previously, notmuch_database_get_directory did not indicate whether or\r
75 not the returned directory object was newly created, which required a\r
76 workaround to distinguish newly created directory objects with no\r
77 child messages from directory objects that had no mtime set but did\r
78 have child messages.  Now that notmuch_database_get_directory\r
79 distinguishes whether or not the directory object exists in the\r
80 database, this workaround is no longer necessary.\r
81 ---\r
82  notmuch-new.c |   36 +++++++-----------------------------\r
83  1 file changed, 7 insertions(+), 29 deletions(-)\r
84 \r
85 diff --git a/notmuch-new.c b/notmuch-new.c\r
86 index a3a8bec..72dd558 100644\r
87 --- a/notmuch-new.c\r
88 +++ b/notmuch-new.c\r
89 @@ -256,7 +256,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
90      notmuch_filenames_t *db_subdirs = NULL;\r
91      time_t stat_time;\r
92      struct stat st;\r
93 -    notmuch_bool_t is_maildir, new_directory;\r
94 +    notmuch_bool_t is_maildir;\r
95      const char **tag;\r
96  \r
97      if (stat (path, &st)) {\r
98 @@ -281,33 +281,12 @@ add_files_recursive (notmuch_database_t *notmuch,\r
99      }\r
100      db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;\r
101  \r
102 -    new_directory = db_mtime ? FALSE : TRUE;\r
103 -\r
104 -    /* XXX This is a temporary workaround.  If we don't update the\r
105 -     * database mtime until after processing messages in this\r
106 -     * directory, then a 0 mtime is *not* sufficient to indicate that\r
107 -     * this directory has no messages or subdirs in the database (for\r
108 -     * example, if an earlier run skipped the mtime update because\r
109 -     * fs_mtime == stat_time, or was interrupted before updating the\r
110 -     * mtime at the end).  To address this, we record a (bogus)\r
111 -     * non-zero value before processing any child messages so that a\r
112 -     * later run won't mistake this for a new directory (and, for\r
113 -     * example, fail to detect removed files and subdirs).\r
114 -     *\r
115 -     * A better solution would be for notmuch_database_get_directory\r
116 -     * to indicate if it really created a new directory or not, either\r
117 -     * by a new out-argument, or by recording this information and\r
118 -     * providing an accessor.\r
119 -     */\r
120 -    if (new_directory && directory)\r
121 -       notmuch_directory_set_mtime (directory, -1);\r
122 -\r
123      /* If the database knows about this directory, then we sort based\r
124       * on strcmp to match the database sorting. Otherwise, we can do\r
125       * inode-based sorting for faster filesystem operation. */\r
126      num_fs_entries = scandir (path, &fs_entries, 0,\r
127 -                             new_directory ?\r
128 -                             dirent_sort_inode : dirent_sort_strcmp_name);\r
129 +                             directory ?\r
130 +                             dirent_sort_strcmp_name : dirent_sort_inode);\r
131  \r
132      if (num_fs_entries == -1) {\r
133         fprintf (stderr, "Error opening directory %s: %s\n",\r
134 @@ -376,13 +355,12 @@ add_files_recursive (notmuch_database_t *notmuch,\r
135       * being discovered until the clock catches up and the directory\r
136       * is modified again).\r
137       */\r
138 -    if (fs_mtime == db_mtime)\r
139 +    if (directory && fs_mtime == db_mtime)\r
140         goto DONE;\r
141  \r
142 -    /* new_directory means a directory that the database has never\r
143 -     * seen before. In that case, we can simply leave db_files and\r
144 -     * db_subdirs NULL. */\r
145 -    if (!new_directory) {\r
146 +    /* If the database has never seen this directory before, we can\r
147 +     * simply leave db_files and db_subdirs NULL. */\r
148 +    if (directory) {\r
149         db_files = notmuch_directory_get_child_files (directory);\r
150         db_subdirs = notmuch_directory_get_child_directories (directory);\r
151      }\r
152 -- \r
153 1.7.10\r
154 \r