]> git.notmuchmail.org Git - notmuch/commitdiff
lib/n_d_needs_upgrade: handle error return from n_d_get_version
authorDavid Bremner <david@tethera.net>
Thu, 16 Jul 2020 22:28:22 +0000 (19:28 -0300)
committerDavid Bremner <david@tethera.net>
Wed, 22 Jul 2020 22:52:55 +0000 (19:52 -0300)
Also clarify documentation of error return from n_d_needs_upgrade.

lib/database.cc
lib/notmuch.h
test/T562-lib-database.sh

index 8ec91987753bafe4e1a60804f830bf05c7699e42..4ff748f6360c494775370c516c1c95a52c3266e6 100644 (file)
@@ -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;
index d9f3003fad32381151d92ea9d847d695daf65a77..f9e9cc413bcbe3daddde0431cbc07dc6f590a149 100644 (file)
@@ -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);
index d7f70415701b261a2e93c7fd420b9f7e68ad26a3..cd202c6e8990284b9d994fcb56aeef8277d46377 100755 (executable)
@@ -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;