From f5f8d6de706b2cd7f4209e6e71636a13a7499abd Mon Sep 17 00:00:00 2001 From: djcb Date: Sun, 6 Jan 2013 15:53:42 +0200 Subject: [PATCH] * mu_store_needs_upgrade --> mu_store_versions_match --- guile/mu-guile.c | 5 +++-- lib/mu-store-priv.hh | 20 ++++++++++++++------ lib/mu-store-read.cc | 11 +++-------- lib/mu-store.h | 9 +++++---- lib/mu-util.h | 2 +- mu/mu-cmd-find.c | 6 +++--- mu/mu-cmd-index.c | 2 +- mu/mu.cc | 4 ++-- toys/mug/mug-msg-list-view.c | 2 +- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/guile/mu-guile.c b/guile/mu-guile.c index 9bb673b5..e40a98cf 100644 --- a/guile/mu-guile.c +++ b/guile/mu-guile.c @@ -89,8 +89,9 @@ mu_guile_init_instance (const char *muhome) return FALSE; err = NULL; - store = mu_store_new_read_only (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), - &err); + store = mu_store_new_read_only + (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), + &err); if (!store) goto errexit; diff --git a/lib/mu-store-priv.hh b/lib/mu-store-priv.hh index 2f1c09c1..3990f420 100644 --- a/lib/mu-store-priv.hh +++ b/lib/mu-store-priv.hh @@ -36,7 +36,7 @@ class MuStoreError { public: - MuStoreError (MuError err, const std::string& what) : + MuStoreError (MuError err, const std::string& what): _err (err), _what(what) {} MuError mu_error () const { return _err; } const std::string& what() const { return _what; } @@ -79,10 +79,18 @@ public: init (path, NULL, false, false); _db = new Xapian::Database (path); - if (mu_store_needs_upgrade(this)) - throw MuStoreError (MU_ERROR_XAPIAN_NOT_UP_TO_DATE, - ("store needs an upgrade")); + if (!mu_store_versions_match(this)) { + char *errstr = + g_strdup_printf ("db version: %s, but we need %s; " + "database rebuild is required", + mu_store_version (this), + MU_STORE_SCHEMA_VERSION); + + MuStoreError exc (MU_ERROR_XAPIAN_VERSION_MISMATCH, errstr); + g_free (errstr); + throw exc; + } MU_WRITE_LOG ("%s: opened %s read-only", __FUNCTION__, this->path()); } @@ -122,8 +130,8 @@ public: MU_STORE_SCHEMA_VERSION, NULL); else if (g_strcmp0 (version, MU_STORE_SCHEMA_VERSION) != 0) { g_free (version); - throw MuStoreError (MU_ERROR_XAPIAN_NOT_UP_TO_DATE, - "store needs an upgrade"); + throw MuStoreError (MU_ERROR_XAPIAN_VERSION_MISMATCH, + "the database needs a rebuild"); } else g_free (version); } diff --git a/lib/mu-store-read.cc b/lib/mu-store-read.cc index 51abe67f..f7fecfa9 100644 --- a/lib/mu-store-read.cc +++ b/lib/mu-store-read.cc @@ -118,17 +118,12 @@ mu_store_version (const MuStore *store) gboolean -mu_store_needs_upgrade (const MuStore *store) +mu_store_versions_match (const MuStore *store) { g_return_val_if_fail (store, TRUE); - MU_WRITE_LOG ("'%s' '%s'\n", mu_store_version(store), MU_STORE_SCHEMA_VERSION); - - if (g_strcmp0 (mu_store_version (store), - MU_STORE_SCHEMA_VERSION) == 0) - return FALSE; - else - return TRUE; + return g_strcmp0 (mu_store_version (store), + MU_STORE_SCHEMA_VERSION) == 0; } diff --git a/lib/mu-store.h b/lib/mu-store.h index 6df0cdee..0dbcb6cd 100644 --- a/lib/mu-store.h +++ b/lib/mu-store.h @@ -353,14 +353,15 @@ gchar* mu_store_database_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT; /** - * check whether the database needs to be upgraded, e.g., when it was - * created with a different version of mu + * check whether the database schema's version is the same as the one + * that the current mu uses. If they are not the same, we'll need a + * database rebuild. * * @param store a MuStore instance * - * @return TRUE if the database needs upgrading, FALSE otherwise + * @return TRUE if the versions are the same, FALSE otherwise. */ -gboolean mu_store_needs_upgrade (const MuStore *store); +gboolean mu_store_versions_match (const MuStore *store); /** * clear the database, ie., remove all of the contents. This is a diff --git a/lib/mu-util.h b/lib/mu-util.h index 8991b22c..f10081aa 100644 --- a/lib/mu-util.h +++ b/lib/mu-util.h @@ -437,7 +437,7 @@ enum _MuError { /* xapian dir is not accessible */ MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE = 14, /* database version is not up-to-date */ - MU_ERROR_XAPIAN_NOT_UP_TO_DATE = 15, + MU_ERROR_XAPIAN_VERSION_MISMATCH = 15, /* missing data for a document */ MU_ERROR_XAPIAN_MISSING_DATA = 16, /* database corruption */ diff --git a/mu/mu-cmd-find.c b/mu/mu-cmd-find.c index c2ea351a..81f4a907 100644 --- a/mu/mu-cmd-find.c +++ b/mu/mu-cmd-find.c @@ -234,9 +234,9 @@ get_query_obj (MuStore *store, GError **err) return NULL; } - if (mu_store_needs_upgrade (store)) { - g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_XAPIAN_NOT_UP_TO_DATE, - "the database is not up-to-date"); + if (!mu_store_versions_match (store)) { + g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_XAPIAN_VERSION_MISMATCH, + "the database needs a rebuild"); return NULL; } diff --git a/mu/mu-cmd-index.c b/mu/mu-cmd-index.c index 5f11a074..a32b3857 100644 --- a/mu/mu-cmd-index.c +++ b/mu/mu-cmd-index.c @@ -203,7 +203,7 @@ database_version_check_and_update (MuStore *store, MuConfig *opts, return mu_store_clear (store, err); } - if (!mu_store_needs_upgrade (store)) + if (mu_store_versions_match (store)) return TRUE; /* ok, nothing to do */ /* ok, database is not up to date */ diff --git a/mu/mu.cc b/mu/mu.cc index 118973bf..97b00713 100644 --- a/mu/mu.cc +++ b/mu/mu.cc @@ -59,8 +59,8 @@ handle_error (MuConfig *conf, MuError merr, GError **err) g_printerr ("maybe mu is already running?\n"); break; case MU_ERROR_XAPIAN_CORRUPTION: - case MU_ERROR_XAPIAN_NOT_UP_TO_DATE: - g_printerr ("database needs update; " + case MU_ERROR_XAPIAN_VERSION_MISMATCH: + g_printerr ("database needs a rebuild; " "try 'mu index --rebuild'\n"); break; case MU_ERROR_XAPIAN_IS_EMPTY: diff --git a/toys/mug/mug-msg-list-view.c b/toys/mug/mug-msg-list-view.c index d738eb3f..e5851fd4 100644 --- a/toys/mug/mug-msg-list-view.c +++ b/toys/mug/mug-msg-list-view.c @@ -311,7 +311,7 @@ mu_result_to_mug_error (MuError r) switch (r) { case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE: return MUG_ERROR_XAPIAN_DIR; - case MU_ERROR_XAPIAN_NOT_UP_TO_DATE: + case MU_ERROR_XAPIAN_VERSION_MISMATCH: return MUG_ERROR_XAPIAN_NOT_UPTODATE; case MU_ERROR_XAPIAN_QUERY: return MUG_ERROR_QUERY;