database: Make find_unique_doc_id enforce uniqueness (for a debug build)
authorCarl Worth <cworth@cworth.org>
Mon, 21 Dec 2009 23:11:32 +0000 (15:11 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 18:32:06 +0000 (10:32 -0800)
Catching any violation of this unique-ness constraint is very much in
line with similar, existing INTERNAL_ERROR cases.

lib/database.cc

index 3ed19772759f2d653fc303c722ec639400a8fa46..5d300732d4a635a369b569ddbe452f39bff73f59 100644 (file)
@@ -246,10 +246,19 @@ find_unique_doc_id (notmuch_database_t *notmuch,
     if (i == end) {
        *doc_id = 0;
        return NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND;
-    } else {
-       *doc_id = *i;
-       return NOTMUCH_PRIVATE_STATUS_SUCCESS;
     }
+
+    *doc_id = *i;
+
+#if DEBUG_DATABASE_SANITY
+    i++;
+
+    if (i != end)
+       INTERNAL_ERROR ("Term %s:%s is not unique as expected.\n",
+                       prefix_name, value);
+#endif
+
+    return NOTMUCH_PRIVATE_STATUS_SUCCESS;
 }
 
 static Xapian::Document