How does notmuch track mails?
[notmuch-archives.git] / 2b / 1a872e66dce68e4ba7f62aa826c88789df4a31
1 Return-Path: <bremner@unb.ca>\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 9FB1240D148\r
6         for <notmuch@notmuchmail.org>; Sun, 24 Oct 2010 14:01:53 -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: -2.6\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham\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 x8VsirHvMrW2 for <notmuch@notmuchmail.org>;\r
16         Sun, 24 Oct 2010 14:01:39 -0700 (PDT)\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
18         by olra.theworths.org (Postfix) with ESMTP id B9FDA40D156\r
19         for <notmuch@notmuchmail.org>; Sun, 24 Oct 2010 14:01:14 -0700 (PDT)\r
20 Received: from rocinante.cs.unb.ca\r
21         (fctnnbsc30w-142167176217.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
22         [142.167.176.217]) (authenticated bits=0)\r
23         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id o9OL1B59017812\r
24         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
25         Sun, 24 Oct 2010 18:01:14 -0300\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.72)\r
27         (envelope-from <bremner@unb.ca>)\r
28         id 1PA7gl-0006Om-El; Sun, 24 Oct 2010 18:01:11 -0300\r
29 From: david@tethera.net\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH 2/4] Add log component to database struct.\r
32 Date: Sun, 24 Oct 2010 18:01:04 -0300\r
33 Message-Id: <1287954066-24512-3-git-send-email-david@tethera.net>\r
34 X-Mailer: git-send-email 1.7.1\r
35 In-Reply-To: <1286803617-17328-1-git-send-email-david@tethera.net>\r
36 References: <1286803617-17328-1-git-send-email-david@tethera.net>\r
37 Cc: David Bremner <bremner@unb.ca>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\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, 24 Oct 2010 21:01:54 -0000\r
51 \r
52 From: David Bremner <bremner@unb.ca>\r
53 \r
54 - add accessor required because the notmuch database struct is opaque\r
55 \r
56 - add a function notmuch_database_open_log to open a log file and\r
57 associate it with an open database.  The reasoning is that this is\r
58 preferable to breaking the notmuch_database_open API at this point.\r
59 ---\r
60  lib/database-private.h |    4 +++-\r
61  lib/database.cc        |   36 ++++++++++++++++++++++++++++++++++++\r
62  lib/notmuch.h          |   12 ++++++++++++\r
63  3 files changed, 51 insertions(+), 1 deletions(-)\r
64 \r
65 diff --git a/lib/database-private.h b/lib/database-private.h\r
66 index bd72f67..da4a72c 100644\r
67 --- a/lib/database-private.h\r
68 +++ b/lib/database-private.h\r
69 @@ -31,7 +31,7 @@\r
70  #include <inttypes.h>\r
71  \r
72  #include "notmuch-private.h"\r
73 -\r
74 +#include "log-private.h"\r
75  #include <xapian.h>\r
76  \r
77  struct _notmuch_database {\r
78 @@ -39,6 +39,8 @@ struct _notmuch_database {\r
79  \r
80      char *path;\r
81  \r
82 +    notmuch_log_t *log;\r
83 +\r
84      notmuch_bool_t needs_upgrade;\r
85      notmuch_database_mode_t mode;\r
86      Xapian::Database *xapian_db;\r
87 diff --git a/lib/database.cc b/lib/database.cc\r
88 index e4ac970..d453a0f 100644\r
89 --- a/lib/database.cc\r
90 +++ b/lib/database.cc\r
91 @@ -683,6 +683,10 @@ notmuch_database_open (const char *path,\r
92             prefix_t *prefix = &PROBABILISTIC_PREFIX[i];\r
93             notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);\r
94         }\r
95 +\r
96 +       /* by default, logging is disabled */\r
97 +       notmuch->log = NULL;\r
98 +\r
99      } catch (const Xapian::Error &error) {\r
100         fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
101                  error.get_msg().c_str());\r
102 @@ -718,12 +722,44 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
103      talloc_free (notmuch);\r
104  }\r
105  \r
106 +/* Attempt to open a log file in the same location as the xapian\r
107 + * database.\r
108 + *\r
109 + * Caller should pass an open notmuch database to it.\r
110 + */\r
111 +\r
112 +notmuch_status_t\r
113 +notmuch_database_open_log (notmuch_database_t *notmuch)\r
114 +{\r
115 +\r
116 +    char *log_path;\r
117 +\r
118 +    log_path = talloc_asprintf(notmuch, "%s/.notmuch/log",\r
119 +                              notmuch_database_get_path (notmuch));\r
120 +\r
121 +    if (log_path == NULL)\r
122 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
123 +\r
124 +    notmuch->log =  notmuch_log_open (notmuch, log_path, NOTMUCH_LOG_BUFFER_LINE);\r
125 +    if (notmuch->log == NULL)\r
126 +       return NOTMUCH_STATUS_FILE_ERROR;\r
127 +\r
128 +    talloc_free(log_path);\r
129 +    return NOTMUCH_STATUS_SUCCESS;\r
130 +}\r
131 +\r
132  const char *\r
133  notmuch_database_get_path (notmuch_database_t *notmuch)\r
134  {\r
135      return notmuch->path;\r
136  }\r
137  \r
138 +notmuch_log_t *\r
139 +notmuch_database_get_log (notmuch_database_t *notmuch)\r
140 +{\r
141 +    return notmuch->log;\r
142 +}\r
143 +\r
144  unsigned int\r
145  notmuch_database_get_version (notmuch_database_t *notmuch)\r
146  {\r
147 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
148 index 1da84aa..54d839a 100644\r
149 --- a/lib/notmuch.h\r
150 +++ b/lib/notmuch.h\r
151 @@ -171,6 +171,14 @@ typedef enum {\r
152  notmuch_database_t *\r
153  notmuch_database_open (const char *path,\r
154                        notmuch_database_mode_t mode);\r
155 +/*\r
156 + * Open the log file associated with a database.\r
157 + *\r
158 + * Caller should pass an open database.\r
159 + */\r
160 +\r
161 +notmuch_status_t\r
162 +notmuch_database_open_log (notmuch_database_t *notmuch);\r
163  \r
164  /* Close the given notmuch database, freeing all associated\r
165   * resources. See notmuch_database_open. */\r
166 @@ -188,6 +196,10 @@ notmuch_database_get_path (notmuch_database_t *database);\r
167  unsigned int\r
168  notmuch_database_get_version (notmuch_database_t *database);\r
169  \r
170 +/* Return the log descriptor of the current database; NULL if no log is open */\r
171 +notmuch_log_t *\r
172 +notmuch_database_get_log (notmuch_database_t *database);\r
173 +\r
174  /* Does this database need to be upgraded before writing to it?\r
175   *\r
176   * If this function returns TRUE then no functions that modify the\r
177 -- \r
178 1.7.1\r
179 \r