diff options
| author | David Bremner <david@tethera.net> | 2022-05-25 07:51:16 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2022-06-25 16:06:18 -0300 |
| commit | 3f27cce71f9f154cb0c2134c32d41c31eb62a239 (patch) | |
| tree | 885c88706efdd7a771944287e4c2c27cfe737e11 /lib/database.cc | |
| parent | 7e654e2a456c552052e9e50b83da73b4d31d8f2b (diff) | |
lib: add NOTMUCH_STATUS_CLOSED_DATABASE, use in _n_d_ensure_writable
In order for a database to actually be writeable, it must be the case that it
is open, not just the correct type of Xapian object. By explicitely
checking, we are able to provide better error reporting, in particular
for the previously broken test in T566-lib-message.
Diffstat (limited to 'lib/database.cc')
| -rw-r--r-- | lib/database.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/database.cc b/lib/database.cc index df83e204..c05d70d3 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -476,6 +476,11 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch) return NOTMUCH_STATUS_READ_ONLY_DATABASE; } + if (! notmuch->open) { + _notmuch_database_log (notmuch, "Cannot write to a closed database.\n"); + return NOTMUCH_STATUS_CLOSED_DATABASE; + } + return NOTMUCH_STATUS_SUCCESS; } @@ -852,9 +857,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, notmuch_query_t *query = NULL; unsigned int count = 0, total = 0; - status = _notmuch_database_ensure_writable (notmuch); - if (status) - return status; + if (_notmuch_database_mode (notmuch) != NOTMUCH_DATABASE_MODE_READ_WRITE) + return NOTMUCH_STATUS_READ_ONLY_DATABASE; db = notmuch->writable_xapian_db; |
