aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-07-16 19:28:22 -0300
committerDavid Bremner <david@tethera.net>2020-07-22 19:52:55 -0300
commitf25fc8e2115fc0fa6fa2a6d1cf3ed2747e163886 (patch)
tree7d665f414f8190d472b05175d4326f25ef71b3c9
parentcf90431cbf2899d675bf09e945c7cbf8f1b4728f (diff)
lib/n_d_needs_upgrade: handle error return from n_d_get_version
Also clarify documentation of error return from n_d_needs_upgrade.
-rw-r--r--lib/database.cc14
-rw-r--r--lib/notmuch.h2
-rwxr-xr-xtest/T562-lib-database.sh1
3 files changed, 13 insertions, 4 deletions
diff --git a/lib/database.cc b/lib/database.cc
index 8ec91987..4ff748f6 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1395,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;
diff --git a/lib/notmuch.h b/lib/notmuch.h
index d9f3003f..f9e9cc41 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -447,6 +447,8 @@ notmuch_database_get_version (notmuch_database_t *database);
* FALSE for a read-only database because there's no way to upgrade a
* read-only database.
*
+ * Also returns FALSE if an error occurs accessing the database.
+ *
*/
notmuch_bool_t
notmuch_database_needs_upgrade (notmuch_database_t *database);
diff --git a/test/T562-lib-database.sh b/test/T562-lib-database.sh
index d7f70415..cd202c6e 100755
--- a/test/T562-lib-database.sh
+++ b/test/T562-lib-database.sh
@@ -132,7 +132,6 @@ EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "check a closed db for upgrade"
-test_subtest_known_broken
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
{
notmuch_bool_t ret;