[Patch v3 2/6] lib/database: add field for last error string

David Bremner david at tethera.net
Sun Dec 28 09:33:46 PST 2014


The idea is to have a logging function setting this string instead of
printing to stderr.
---
 lib/database-private.h | 4 ++++
 lib/database.cc        | 7 +++++++
 lib/notmuch.h          | 7 +++++++
 3 files changed, 18 insertions(+)

diff --git a/lib/database-private.h b/lib/database-private.h
index 15e03cc..7efd98b 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -146,6 +146,10 @@ struct _notmuch_database {
     unsigned int last_doc_id;
     uint64_t last_thread_id;
 
+    /* error reporting; this value persists only until the
+     * next library call. May be NULL */
+    char *status_string;
+
     Xapian::QueryParser *query_parser;
     Xapian::TermGenerator *term_gen;
     Xapian::ValueRangeProcessor *value_range_processor;
diff --git a/lib/database.cc b/lib/database.cc
index 4f4e871..18db902 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -858,6 +858,7 @@ notmuch_database_open_verbose (const char *path,
 
     notmuch = talloc_zero (NULL, notmuch_database_t);
     notmuch->exception_reported = FALSE;
+    notmuch->status_string = NULL;
     notmuch->path = talloc_strdup (notmuch, path);
 
     if (notmuch->path[strlen (notmuch->path) - 1] == '/')
@@ -2543,3 +2544,9 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 	return NULL;
     }
 }
+
+const char *
+notmuch_database_status_string (notmuch_database_t *notmuch)
+{
+    return notmuch->status_string;
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 0dfac8f..2ab2998 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -302,6 +302,13 @@ notmuch_database_open_verbose (const char *path,
 			       char **error_message);
 
 /**
+ * Retrieve last status string for given database.
+ *
+ */
+const char *
+notmuch_database_status_string (notmuch_database_t *notmuch);
+
+/**
  * Commit changes and close the given notmuch database.
  *
  * After notmuch_database_close has been called, calls to other
-- 
2.1.3



More information about the notmuch mailing list