X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fdirectory.cc;h=461c0cc367801b72819f429013a214552efc279d;hb=cb8e4bc9c0406391cedde012dfcd7ea8f6b8ef46;hp=196f78059ecbace2e347aeb48222c787bf7e4060;hpb=d807e28f43579ecc91aa40ae3e42760991c2f810;p=notmuch diff --git a/lib/directory.cc b/lib/directory.cc index 196f7805..461c0cc3 100644 --- a/lib/directory.cc +++ b/lib/directory.cc @@ -81,12 +81,18 @@ _notmuch_filenames_create (void *ctx, notmuch_bool_t notmuch_filenames_has_more (notmuch_filenames_t *filenames) { + if (filenames == NULL) + return NULL; + return (filenames->iterator != filenames->end); } const char * notmuch_filenames_get (notmuch_filenames_t *filenames) { + if (filenames == NULL || filenames->iterator == filenames->end) + return NULL; + if (filenames->filename == NULL) { std::string term = *filenames->iterator; @@ -101,6 +107,9 @@ notmuch_filenames_get (notmuch_filenames_t *filenames) void notmuch_filenames_advance (notmuch_filenames_t *filenames) { + if (filenames == NULL) + return; + if (filenames->filename) { talloc_free (filenames->filename); filenames->filename = NULL; @@ -113,6 +122,9 @@ notmuch_filenames_advance (notmuch_filenames_t *filenames) void notmuch_filenames_destroy (notmuch_filenames_t *filenames) { + if (filenames == NULL) + return; + talloc_free (filenames); } @@ -170,11 +182,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 (notmuch->xapian_db); @@ -256,11 +265,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 (notmuch->xapian_db);