X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=96300008765e445f146ec2b3ce93b03df792b1cf;hp=dcfad8cf2c67306ea9d956d0af9309db06e78187;hb=b9bf3f44eacd42ce53885c79f9dad8d82c76f13d;hpb=65a6b86873a471bb87d30a8617a87857103cd8b6 diff --git a/lib/database.cc b/lib/database.cc index dcfad8cf..96300008 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -20,6 +20,7 @@ #include "database-private.h" #include "parse-time-vrp.h" +#include "query-fp.h" #include "string-util.h" #include @@ -1000,6 +1001,14 @@ notmuch_database_open_verbose (const char *path, notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); +#if HAVE_XAPIAN_FIELD_PROCESSOR + /* This currently relies on the query parser to pass anything + * with a .. to the range processor */ + notmuch->date_field_processor = new DateFieldProcessor(); + notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor); + notmuch->query_field_processor = new QueryFieldProcessor (*notmuch->query_parser, notmuch); + notmuch->query_parser->add_boolean_prefix("query", notmuch->query_field_processor); +#endif notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); @@ -1410,8 +1419,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, ""); - 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); + query = NULL; } if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) { t_end = db->allterms_end ("XTIMESTAMP"); @@ -1443,9 +1459,10 @@ notmuch_database_upgrade (notmuch_database_t *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)) { @@ -1492,6 +1509,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, } notmuch_query_destroy (query); + query = NULL; } /* Perform per-directory upgrades. */ @@ -1612,6 +1630,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, sigaction (SIGALRM, &action, NULL); } + if (query) + notmuch_query_destroy (query); + talloc_free (local); return status; } @@ -1623,6 +1644,9 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch) notmuch->atomic_nesting > 0) goto DONE; + if (notmuch_database_needs_upgrade(notmuch)) + return NOTMUCH_STATUS_UPGRADE_REQUIRED; + try { (static_cast (notmuch->xapian_db))->begin_transaction (false); } catch (const Xapian::Error &error) { @@ -1746,18 +1770,11 @@ _notmuch_database_split_path (void *ctx, slash = path + strlen (path) - 1; /* First, skip trailing slashes. */ - while (slash != path) { - if (*slash != '/') - break; - + while (slash != path && *slash == '/') --slash; - } /* Then, find a slash. */ - while (slash != path) { - if (*slash == '/') - break; - + while (slash != path && *slash != '/') { if (basename) *basename = slash; @@ -1765,12 +1782,8 @@ _notmuch_database_split_path (void *ctx, } /* Finally, skip multiple slashes. */ - while (slash != path) { - if (*slash != '/') - break; - + while (slash != path && *(slash - 1) == '/') --slash; - } if (slash == path) { if (directory) @@ -1779,7 +1792,7 @@ _notmuch_database_split_path (void *ctx, *basename = path; } else { if (directory) - *directory = talloc_strndup (ctx, path, slash - path + 1); + *directory = talloc_strndup (ctx, path, slash - path); } return NOTMUCH_STATUS_SUCCESS;