[PATCH 04/10] lib/n_d_needs_upgrade: handle error return from n_d_get_version

Subject: [PATCH 04/10] lib/n_d_needs_upgrade: handle error return from n_d_get_version

Date: Sat, 18 Jul 2020 12:07:45 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


Also clarify documentation of error return from n_d_needs_upgrade.
---
 lib/database.cc           | 14 +++++++++++---
 lib/notmuch.h             |  2 ++
 test/T562-lib-database.sh |  1 -
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 27861970..25d34253 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 45ecc59b..b8b89a4a 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 0af7587a..4bcbc805 100755
--- a/test/T562-lib-database.sh
+++ b/test/T562-lib-database.sh
@@ -130,7 +130,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;
-- 
2.27.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: