X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=bcea88b029e7a097a7887c7570e5715e7a78fc76;hp=fb38664789e50c360df7c5a2c400e6015be81904;hb=e2341cbc09b503f996fd46b68f9d96ae6004025b;hpb=f379aa52845f5594aa6cc2e7cf131d5f57202bbf diff --git a/lib/database.cc b/lib/database.cc index fb386647..bcea88b0 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -441,7 +441,7 @@ notmuch_database_create (const char *path) } notmuch = notmuch_database_open (path, - NOTMUCH_DATABASE_MODE_WRITABLE); + NOTMUCH_DATABASE_MODE_READ_WRITE); DONE: if (notmuch_path) @@ -480,6 +480,7 @@ notmuch_database_open (const char *path, } notmuch = talloc (NULL, notmuch_database_t); + notmuch->exception_reported = FALSE; notmuch->path = talloc_strdup (notmuch, path); if (notmuch->path[strlen (notmuch->path) - 1] == '/') @@ -487,7 +488,7 @@ notmuch_database_open (const char *path, notmuch->mode = mode; try { - if (mode == NOTMUCH_DATABASE_MODE_WRITABLE) { + if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) { notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path, Xapian::DB_CREATE_OR_OPEN); } else { @@ -513,7 +514,7 @@ notmuch_database_open (const char *path, notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); } } catch (const Xapian::Error &error) { - fprintf (stderr, "A Xapian exception occurred: %s\n", + fprintf (stderr, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str()); notmuch = NULL; } @@ -530,8 +531,15 @@ notmuch_database_open (const char *path, void notmuch_database_close (notmuch_database_t *notmuch) { - if (notmuch->mode == NOTMUCH_DATABASE_MODE_WRITABLE) - (static_cast (notmuch->xapian_db))->flush (); + try { + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE) + (static_cast (notmuch->xapian_db))->flush (); + } catch (const Xapian::Error &error) { + if (! notmuch->exception_reported) { + fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n", + error.get_msg().c_str()); + } + } delete notmuch->term_gen; delete notmuch->query_parser; @@ -583,7 +591,7 @@ notmuch_database_set_timestamp (notmuch_database_t *notmuch, notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; char *db_key = NULL; - if (notmuch->mode == NOTMUCH_DATABASE_MODE_READONLY) { + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) { fprintf (stderr, "Attempted to update a read-only database.\n"); return NOTMUCH_STATUS_READONLY_DATABASE; } @@ -608,9 +616,10 @@ notmuch_database_set_timestamp (notmuch_database_t *notmuch, db->replace_document (doc_id, doc); } - } catch (Xapian::Error &error) { - fprintf (stderr, "A Xapian exception occurred: %s.\n", + } catch (const Xapian::Error &error) { + fprintf (stderr, "A Xapian exception occurred setting timestamp: %s.\n", error.get_msg().c_str()); + notmuch->exception_reported = TRUE; ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; } @@ -983,8 +992,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch, _notmuch_message_sync (message); } catch (const Xapian::Error &error) { - fprintf (stderr, "A Xapian exception occurred: %s.\n", - error.get_msg().c_str()); + fprintf (stderr, "A Xapian exception occurred adding message: %s.\n", + error.get_description().c_str()); + notmuch->exception_reported = TRUE; ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; goto DONE; }