]> git.notmuchmail.org Git - notmuch/blobdiff - lib/directory.cc
lib: Eliminate some redundant includes of xapian.h
[notmuch] / lib / directory.cc
index d5015e0ac6f351102b894d0e5efe96f437575408..2540ca7647fa99e976593d052fed6b55437c9380 100644 (file)
@@ -21,8 +21,6 @@
 #include "notmuch-private.h"
 #include "database-private.h"
 
-#include <xapian.h>
-
 struct _notmuch_filenames {
     Xapian::TermIterator iterator;
     Xapian::TermIterator end;
@@ -52,7 +50,7 @@ _notmuch_filenames_destructor (notmuch_filenames_t *filenames)
  * iterating over the non-prefixed portion of terms sharing a common
  * prefix.
  */
-notmuch_filenames_t *
+static notmuch_filenames_t *
 _notmuch_filenames_create (void *ctx,
                           notmuch_database_t *notmuch,
                           const char *prefix)
@@ -79,7 +77,7 @@ _notmuch_filenames_create (void *ctx,
 }
 
 notmuch_bool_t
-notmuch_filenames_has_more (notmuch_filenames_t *filenames)
+notmuch_filenames_valid (notmuch_filenames_t *filenames)
 {
     if (filenames == NULL)
        return NULL;
@@ -105,7 +103,7 @@ notmuch_filenames_get (notmuch_filenames_t *filenames)
 }
 
 void
-notmuch_filenames_advance (notmuch_filenames_t *filenames)
+notmuch_filenames_move_to_next (notmuch_filenames_t *filenames)
 {
     if (filenames == NULL)
        return;
@@ -182,11 +180,8 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
 
     path = _notmuch_database_relative_path (notmuch, path);
 
-    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
-       fprintf (stderr, "Attempted to update a read-only database.\n");
-       *status_ret = NOTMUCH_STATUS_READONLY_DATABASE;
-       return NULL;
-    }
+    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
+       INTERNAL_ERROR ("Failure to ensure database is writable");
 
     db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
 
@@ -216,7 +211,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
            Xapian::docid parent_id;
            char *term = talloc_asprintf (local, "%s%s",
                                          _find_prefix ("directory"), db_path);
-           directory->doc.add_term (term);
+           directory->doc.add_term (term, 0);
 
            directory->doc.set_data (path);
 
@@ -228,13 +223,14 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
                term = talloc_asprintf (local, "%s%u:%s",
                                        _find_prefix ("directory-direntry"),
                                        parent_id, basename);
-               directory->doc.add_term (term);
+               directory->doc.add_term (term, 0);
            }
 
            directory->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
                                      Xapian::sortable_serialise (0));
 
-           directory->document_id = db->add_document (directory->doc);
+           directory->document_id = _notmuch_database_generate_doc_id (notmuch);
+           db->replace_document (directory->document_id, directory->doc);
            talloc_free (local);
        }
 
@@ -268,11 +264,11 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
 {
     notmuch_database_t *notmuch = directory->notmuch;
     Xapian::WritableDatabase *db;
+    notmuch_status_t status;
 
-    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
-       fprintf (stderr, "Attempted to update a read-only database.\n");
-       return NOTMUCH_STATUS_READONLY_DATABASE;
-    }
+    status = _notmuch_database_ensure_writable (notmuch);
+    if (status)
+       return status;
 
     db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);