* update database up-to-date and/or empty checks
This commit is contained in:
@ -137,6 +137,11 @@ mu_query_xapian_new (const char* xpath)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mu_util_xapian_db_is_empty (xpath)) {
|
||||||
|
g_warning ("database %s is empty; nothing to do", xpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mu_util_xapian_db_version_up_to_date (xpath)) {
|
if (!mu_util_xapian_db_version_up_to_date (xpath)) {
|
||||||
g_warning ("%s is not up-to-date, needs a full update",
|
g_warning ("%s is not up-to-date, needs a full update",
|
||||||
xpath);
|
xpath);
|
||||||
|
|||||||
@ -32,13 +32,12 @@ mu_util_xapian_db_version (const gchar *xpath)
|
|||||||
{
|
{
|
||||||
g_return_val_if_fail (xpath, NULL);
|
g_return_val_if_fail (xpath, NULL);
|
||||||
|
|
||||||
try {
|
|
||||||
if (!access(xpath, F_OK) == 0) {
|
if (!access(xpath, F_OK) == 0) {
|
||||||
g_warning ("cannot access %s: %s",
|
g_warning ("cannot access %s: %s", xpath, strerror(errno));
|
||||||
xpath, strerror(errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
Xapian::Database db (xpath);
|
Xapian::Database db (xpath);
|
||||||
const std::string version
|
const std::string version
|
||||||
(db.get_metadata (MU_XAPIAN_VERSION_KEY));
|
(db.get_metadata (MU_XAPIAN_VERSION_KEY));
|
||||||
@ -74,6 +73,26 @@ mu_util_xapian_db_version_up_to_date (const gchar *xpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mu_util_xapian_db_is_empty (const gchar* xpath)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (xpath, TRUE);
|
||||||
|
|
||||||
|
/* it's 'empty' (non-existant) */
|
||||||
|
if (access(xpath, F_OK) != 0 && errno == ENOENT)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Xapian::Database db (xpath);
|
||||||
|
return db.get_doccount() == 0 ? TRUE : FALSE;
|
||||||
|
|
||||||
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_util_xapian_clear_database (const gchar *xpath)
|
mu_util_xapian_clear_database (const gchar *xpath)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,6 +38,16 @@ G_BEGIN_DECLS
|
|||||||
gchar* mu_util_xapian_db_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT;
|
gchar* mu_util_xapian_db_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether the database is empty (contains 0 documents); in
|
||||||
|
* addition, a non-existing database is considered 'empty' too
|
||||||
|
*
|
||||||
|
* @param xpath path to the xapian database
|
||||||
|
*
|
||||||
|
* @return TRUE if the database is empty, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_util_xapian_db_is_empty (const gchar *xpath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the 'schema' of the current database is up-to-date
|
* check if the 'schema' of the current database is up-to-date
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user