In order to mimic the "best effort" API of Xapian to provide
information from a closed database when possible, do not
destroy the Xapian database object too early.
Because the pointer to a Xapian database is no longer nulled on close,
introduce a flag to track whether the notmuch database is open or not.
/* true if changes have been made in this atomic section */
bool atomic_dirty;
Xapian::Database *xapian_db;
/* true if changes have been made in this atomic section */
bool atomic_dirty;
Xapian::Database *xapian_db;
/* Bit mask of features used by this database. This is a
* bitwise-OR of NOTMUCH_FEATURE_* values (above). */
enum _notmuch_features features;
/* Bit mask of features used by this database. This is a
* bitwise-OR of NOTMUCH_FEATURE_* values (above). */
enum _notmuch_features features;
*database = notmuch;
else
talloc_free (notmuch);
*database = notmuch;
else
talloc_free (notmuch);
+
+ if (notmuch)
+ notmuch->open = true;
+
/* Many Xapian objects (and thus notmuch objects) hold references to
* the database, so merely deleting the database may not suffice to
* close it. Thus, we explicitly close it here. */
/* Many Xapian objects (and thus notmuch objects) hold references to
* the database, so merely deleting the database may not suffice to
* close it. Thus, we explicitly close it here. */
- if (notmuch->xapian_db != NULL) {
try {
/* If there's an outstanding transaction, it's unclear if
* closing the Xapian database commits everything up to
try {
/* If there's an outstanding transaction, it's unclear if
* closing the Xapian database commits everything up to
-
- delete notmuch->term_gen;
- notmuch->term_gen = NULL;
- delete notmuch->query_parser;
- notmuch->query_parser = NULL;
- delete notmuch->xapian_db;
- notmuch->xapian_db = NULL;
- delete notmuch->value_range_processor;
- notmuch->value_range_processor = NULL;
- delete notmuch->date_range_processor;
- notmuch->date_range_processor = NULL;
- delete notmuch->last_mod_range_processor;
- notmuch->last_mod_range_processor = NULL;
-
notmuch_status_t status;
status = notmuch_database_close (notmuch);
notmuch_status_t status;
status = notmuch_database_close (notmuch);
+
+ delete notmuch->term_gen;
+ notmuch->term_gen = NULL;
+ delete notmuch->query_parser;
+ notmuch->query_parser = NULL;
+ delete notmuch->xapian_db;
+ notmuch->xapian_db = NULL;
+ delete notmuch->value_range_processor;
+ notmuch->value_range_processor = NULL;
+ delete notmuch->date_range_processor;
+ notmuch->date_range_processor = NULL;
+ delete notmuch->last_mod_range_processor;
+ notmuch->last_mod_range_processor = NULL;
+
talloc_free (notmuch);
return status;
talloc_free (notmuch);
return status;