X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=4ff748f6360c494775370c516c1c95a52c3266e6;hp=cfb19ccb22c3752f270cd75e08b1b3d8ce97d93f;hb=f25fc8e2115fc0fa6fa2a6d1cf3ed2747e163886;hpb=095d3d7134f5668b96cf1d70997d3f110b03c898;ds=sidebyside diff --git a/lib/database.cc b/lib/database.cc index cfb19ccb..4ff748f6 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -58,6 +58,17 @@ typedef struct { #define DB_ACTION Xapian::DB_CREATE_OR_OPEN #endif +#define LOG_XAPIAN_EXCEPTION(message, error) _log_xapian_exception (__location__, message, error) + +static void +_log_xapian_exception (const char *where, notmuch_database_t *notmuch, const Xapian::Error error) { + _notmuch_database_log (notmuch, + "A Xapian exception occurred at %s: %s\n", + where, + error.get_msg ().c_str ()); + notmuch->exception_reported = true; +} + /* Here's the current schema for our database (for NOTMUCH_DATABASE_VERSION): * * We currently have three different types of documents (mail, ghost, @@ -1360,7 +1371,13 @@ notmuch_database_get_version (notmuch_database_t *notmuch) const char *str; char *end; - version_string = notmuch->xapian_db->get_metadata ("version"); + try { + version_string = notmuch->xapian_db->get_metadata ("version"); + } catch (const Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (notmuch, error); + return 0; + } + if (version_string.empty ()) return 0; @@ -1378,9 +1395,17 @@ notmuch_database_get_version (notmuch_database_t *notmuch) notmuch_bool_t notmuch_database_needs_upgrade (notmuch_database_t *notmuch) { - return notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE && - ((NOTMUCH_FEATURES_CURRENT & ~notmuch->features) || - (notmuch_database_get_version (notmuch) < NOTMUCH_DATABASE_VERSION)); + unsigned int version; + + if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_WRITE) + return FALSE; + + if (NOTMUCH_FEATURES_CURRENT & ~notmuch->features) + return TRUE; + + version = notmuch_database_get_version (notmuch); + + return (version > 0 && version < NOTMUCH_DATABASE_VERSION); } static volatile sig_atomic_t do_progress_notify = 0;