]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
lib: fix handling of one character long directory names at top level
[notmuch] / lib / database.cc
index dcfad8cf2c67306ea9d956d0af9309db06e78187..b8486f7d5271771648ef0ff1ec71c8887a43b391 100644 (file)
@@ -1410,8 +1410,15 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
         NOTMUCH_FEATURE_LAST_MOD)) {
        query = notmuch_query_create (notmuch, "");
        (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
         NOTMUCH_FEATURE_LAST_MOD)) {
        query = notmuch_query_create (notmuch, "");
-       total += notmuch_query_count_messages (query);
+       unsigned msg_count;
+
+       status = notmuch_query_count_messages_st (query, &msg_count);
+       if (status)
+           goto DONE;
+
+       total += msg_count;
        notmuch_query_destroy (query);
        notmuch_query_destroy (query);
+       query = NULL;
     }
     if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
        t_end = db->allterms_end ("XTIMESTAMP");
     }
     if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
        t_end = db->allterms_end ("XTIMESTAMP");
@@ -1443,9 +1450,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
 
        query = notmuch_query_create (notmuch, "");
 
 
        query = notmuch_query_create (notmuch, "");
 
-       /* XXX: this should use the _st version, but needs an error
-          path */
-       for (messages = notmuch_query_search_messages (query);
+       status = notmuch_query_search_messages_st (query, &messages);
+       if (status)
+           goto DONE;
+       for (;
             notmuch_messages_valid (messages);
             notmuch_messages_move_to_next (messages))
        {
             notmuch_messages_valid (messages);
             notmuch_messages_move_to_next (messages))
        {
@@ -1492,6 +1500,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        }
 
        notmuch_query_destroy (query);
        }
 
        notmuch_query_destroy (query);
+       query = NULL;
     }
 
     /* Perform per-directory upgrades. */
     }
 
     /* Perform per-directory upgrades. */
@@ -1612,6 +1621,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        sigaction (SIGALRM, &action, NULL);
     }
 
        sigaction (SIGALRM, &action, NULL);
     }
 
+    if (query)
+       notmuch_query_destroy (query);
+
     talloc_free (local);
     return status;
 }
     talloc_free (local);
     return status;
 }
@@ -1623,6 +1635,9 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
        notmuch->atomic_nesting > 0)
        goto DONE;
 
        notmuch->atomic_nesting > 0)
        goto DONE;
 
+       if (notmuch_database_needs_upgrade(notmuch))
+               return NOTMUCH_STATUS_UPGRADE_REQUIRED;
+
     try {
        (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
     } catch (const Xapian::Error &error) {
     try {
        (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
     } catch (const Xapian::Error &error) {
@@ -1766,7 +1781,7 @@ _notmuch_database_split_path (void *ctx,
 
     /* Finally, skip multiple slashes. */
     while (slash != path) {
 
     /* Finally, skip multiple slashes. */
     while (slash != path) {
-       if (*slash != '/')
+       if (*(slash - 1) != '/')
            break;
 
        --slash;
            break;
 
        --slash;
@@ -1779,7 +1794,7 @@ _notmuch_database_split_path (void *ctx,
            *basename = path;
     } else {
        if (directory)
            *basename = path;
     } else {
        if (directory)
-           *directory = talloc_strndup (ctx, path, slash - path + 1);
+           *directory = talloc_strndup (ctx, path, slash - path);
     }
 
     return NOTMUCH_STATUS_SUCCESS;
     }
 
     return NOTMUCH_STATUS_SUCCESS;