Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 9FB1240D148 for ; Sun, 24 Oct 2010 14:01:53 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.6 X-Spam-Level: X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x8VsirHvMrW2 for ; Sun, 24 Oct 2010 14:01:39 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) by olra.theworths.org (Postfix) with ESMTP id B9FDA40D156 for ; Sun, 24 Oct 2010 14:01:14 -0700 (PDT) Received: from rocinante.cs.unb.ca (fctnnbsc30w-142167176217.pppoe-dynamic.High-Speed.nb.bellaliant.net [142.167.176.217]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id o9OL1B59017812 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Sun, 24 Oct 2010 18:01:14 -0300 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.72) (envelope-from ) id 1PA7gl-0006Om-El; Sun, 24 Oct 2010 18:01:11 -0300 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH 2/4] Add log component to database struct. Date: Sun, 24 Oct 2010 18:01:04 -0300 Message-Id: <1287954066-24512-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1286803617-17328-1-git-send-email-david@tethera.net> References: <1286803617-17328-1-git-send-email-david@tethera.net> Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Oct 2010 21:01:54 -0000 From: David Bremner - add accessor required because the notmuch database struct is opaque - add a function notmuch_database_open_log to open a log file and associate it with an open database. The reasoning is that this is preferable to breaking the notmuch_database_open API at this point. --- lib/database-private.h | 4 +++- lib/database.cc | 36 ++++++++++++++++++++++++++++++++++++ lib/notmuch.h | 12 ++++++++++++ 3 files changed, 51 insertions(+), 1 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index bd72f67..da4a72c 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -31,7 +31,7 @@ #include #include "notmuch-private.h" - +#include "log-private.h" #include struct _notmuch_database { @@ -39,6 +39,8 @@ struct _notmuch_database { char *path; + notmuch_log_t *log; + notmuch_bool_t needs_upgrade; notmuch_database_mode_t mode; Xapian::Database *xapian_db; diff --git a/lib/database.cc b/lib/database.cc index e4ac970..d453a0f 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -683,6 +683,10 @@ notmuch_database_open (const char *path, prefix_t *prefix = &PROBABILISTIC_PREFIX[i]; notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); } + + /* by default, logging is disabled */ + notmuch->log = NULL; + } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str()); @@ -718,12 +722,44 @@ notmuch_database_close (notmuch_database_t *notmuch) talloc_free (notmuch); } +/* Attempt to open a log file in the same location as the xapian + * database. + * + * Caller should pass an open notmuch database to it. + */ + +notmuch_status_t +notmuch_database_open_log (notmuch_database_t *notmuch) +{ + + char *log_path; + + log_path = talloc_asprintf(notmuch, "%s/.notmuch/log", + notmuch_database_get_path (notmuch)); + + if (log_path == NULL) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + notmuch->log = notmuch_log_open (notmuch, log_path, NOTMUCH_LOG_BUFFER_LINE); + if (notmuch->log == NULL) + return NOTMUCH_STATUS_FILE_ERROR; + + talloc_free(log_path); + return NOTMUCH_STATUS_SUCCESS; +} + const char * notmuch_database_get_path (notmuch_database_t *notmuch) { return notmuch->path; } +notmuch_log_t * +notmuch_database_get_log (notmuch_database_t *notmuch) +{ + return notmuch->log; +} + unsigned int notmuch_database_get_version (notmuch_database_t *notmuch) { diff --git a/lib/notmuch.h b/lib/notmuch.h index 1da84aa..54d839a 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -171,6 +171,14 @@ typedef enum { notmuch_database_t * notmuch_database_open (const char *path, notmuch_database_mode_t mode); +/* + * Open the log file associated with a database. + * + * Caller should pass an open database. + */ + +notmuch_status_t +notmuch_database_open_log (notmuch_database_t *notmuch); /* Close the given notmuch database, freeing all associated * resources. See notmuch_database_open. */ @@ -188,6 +196,10 @@ notmuch_database_get_path (notmuch_database_t *database); unsigned int notmuch_database_get_version (notmuch_database_t *database); +/* Return the log descriptor of the current database; NULL if no log is open */ +notmuch_log_t * +notmuch_database_get_log (notmuch_database_t *database); + /* Does this database need to be upgraded before writing to it? * * If this function returns TRUE then no functions that modify the -- 1.7.1