* mu_store_needs_upgrade --> mu_store_versions_match

This commit is contained in:
djcb 2013-01-06 15:53:42 +02:00
parent e8f4f5976d
commit f5f8d6de70
9 changed files with 33 additions and 28 deletions

View File

@ -89,7 +89,8 @@ mu_guile_init_instance (const char *muhome)
return FALSE; return FALSE;
err = NULL; err = NULL;
store = mu_store_new_read_only (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), store = mu_store_new_read_only
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
&err); &err);
if (!store) if (!store)
goto errexit; goto errexit;

View File

@ -79,10 +79,18 @@ public:
init (path, NULL, false, false); init (path, NULL, false, false);
_db = new Xapian::Database (path); _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()); MU_WRITE_LOG ("%s: opened %s read-only", __FUNCTION__, this->path());
} }
@ -122,8 +130,8 @@ public:
MU_STORE_SCHEMA_VERSION, NULL); MU_STORE_SCHEMA_VERSION, NULL);
else if (g_strcmp0 (version, MU_STORE_SCHEMA_VERSION) != 0) { else if (g_strcmp0 (version, MU_STORE_SCHEMA_VERSION) != 0) {
g_free (version); g_free (version);
throw MuStoreError (MU_ERROR_XAPIAN_NOT_UP_TO_DATE, throw MuStoreError (MU_ERROR_XAPIAN_VERSION_MISMATCH,
"store needs an upgrade"); "the database needs a rebuild");
} else } else
g_free (version); g_free (version);
} }

View File

@ -118,17 +118,12 @@ mu_store_version (const MuStore *store)
gboolean gboolean
mu_store_needs_upgrade (const MuStore *store) mu_store_versions_match (const MuStore *store)
{ {
g_return_val_if_fail (store, TRUE); g_return_val_if_fail (store, TRUE);
MU_WRITE_LOG ("'%s' '%s'\n", mu_store_version(store), MU_STORE_SCHEMA_VERSION); return g_strcmp0 (mu_store_version (store),
MU_STORE_SCHEMA_VERSION) == 0;
if (g_strcmp0 (mu_store_version (store),
MU_STORE_SCHEMA_VERSION) == 0)
return FALSE;
else
return TRUE;
} }

View File

@ -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 * check whether the database schema's version is the same as the one
* created with a different version of mu * that the current mu uses. If they are not the same, we'll need a
* database rebuild.
* *
* @param store a MuStore instance * @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 * clear the database, ie., remove all of the contents. This is a

View File

@ -437,7 +437,7 @@ enum _MuError {
/* xapian dir is not accessible */ /* xapian dir is not accessible */
MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE = 14, MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE = 14,
/* database version is not up-to-date */ /* 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 */ /* missing data for a document */
MU_ERROR_XAPIAN_MISSING_DATA = 16, MU_ERROR_XAPIAN_MISSING_DATA = 16,
/* database corruption */ /* database corruption */

View File

@ -234,9 +234,9 @@ get_query_obj (MuStore *store, GError **err)
return NULL; return NULL;
} }
if (mu_store_needs_upgrade (store)) { if (!mu_store_versions_match (store)) {
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_XAPIAN_NOT_UP_TO_DATE, g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_XAPIAN_VERSION_MISMATCH,
"the database is not up-to-date"); "the database needs a rebuild");
return NULL; return NULL;
} }

View File

@ -203,7 +203,7 @@ database_version_check_and_update (MuStore *store, MuConfig *opts,
return mu_store_clear (store, err); return mu_store_clear (store, err);
} }
if (!mu_store_needs_upgrade (store)) if (mu_store_versions_match (store))
return TRUE; /* ok, nothing to do */ return TRUE; /* ok, nothing to do */
/* ok, database is not up to date */ /* ok, database is not up to date */

View File

@ -59,8 +59,8 @@ handle_error (MuConfig *conf, MuError merr, GError **err)
g_printerr ("maybe mu is already running?\n"); g_printerr ("maybe mu is already running?\n");
break; break;
case MU_ERROR_XAPIAN_CORRUPTION: case MU_ERROR_XAPIAN_CORRUPTION:
case MU_ERROR_XAPIAN_NOT_UP_TO_DATE: case MU_ERROR_XAPIAN_VERSION_MISMATCH:
g_printerr ("database needs update; " g_printerr ("database needs a rebuild; "
"try 'mu index --rebuild'\n"); "try 'mu index --rebuild'\n");
break; break;
case MU_ERROR_XAPIAN_IS_EMPTY: case MU_ERROR_XAPIAN_IS_EMPTY:

View File

@ -311,7 +311,7 @@ mu_result_to_mug_error (MuError r)
switch (r) { switch (r) {
case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE: case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE:
return MUG_ERROR_XAPIAN_DIR; 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; return MUG_ERROR_XAPIAN_NOT_UPTODATE;
case MU_ERROR_XAPIAN_QUERY: case MU_ERROR_XAPIAN_QUERY:
return MUG_ERROR_QUERY; return MUG_ERROR_QUERY;