* add mu_util_xapian_is_locked and use it

This commit is contained in:
Dirk-Jan C. Binnema 2011-01-14 07:47:19 +02:00
parent 2e4a94d0d6
commit 91cbdd6b71
3 changed files with 34 additions and 1 deletions

View File

@ -140,3 +140,19 @@ mu_util_xapian_clear (const gchar *xpath)
return FALSE;
}
gboolean
mu_util_xapian_is_locked (const gchar *xpath)
{
g_return_val_if_fail (xpath, FALSE);
try {
Xapian::WritableDatabase db (xpath, Xapian::DB_OPEN);
} catch (const Xapian::DatabaseLockError& xer) {
return TRUE;
} catch (const Xapian::Error &xer) {
g_warning ("%s: error: %s", __FUNCTION__, xer.get_msg().c_str());
}
return FALSE;
}

View File

@ -184,6 +184,16 @@ gboolean mu_util_xapian_is_empty (const gchar *xpath);
gboolean mu_util_xapian_clear (const gchar *xpath);
/**
* check if the database is locked for writing
*
* @param xpath path to a xapian database
*
* @return TRUE if it is locked, FALSE otherwise (or in case of error)
*/
gboolean mu_util_xapian_is_locked (const gchar *xpath);
/**
* convert a string array in to a string, with the elements separated
* by ' '
@ -252,10 +262,14 @@ unsigned char mu_util_get_dtype_with_lstat (const char *path);
g_set_error ((GE),0,MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK, \
"%s: xapian error '%s'", \
__FUNCTION__, xerr.get_msg().c_str()); \
} catch (const Xapian::DatabaseCorruptError &xerr ) { \
} catch (const Xapian::DatabaseCorruptError &xerr) { \
g_set_error ((GE),0,MU_ERROR_XAPIAN_CORRUPTION, \
"%s: xapian error '%s'", \
__FUNCTION__, xerr.get_msg().c_str()); \
} catch (const Xapian::DatabaseError &xerr) { \
g_set_error ((GE),0,MU_ERROR_XAPIAN, \
"%s: xapian error '%s'", \
__FUNCTION__, xerr.get_msg().c_str()); \
} catch (const Xapian::Error &xerr) { \
g_set_error ((GE),0,(E), "%s: xapian error '%s'", \
__FUNCTION__, xerr.get_msg().c_str()); \

View File

@ -62,6 +62,9 @@ reindex (MugData *mugdata)
MuIndex *midx;
GError *err;
if (mu_util_xapian_is_locked (mu_runtime_xapian_dir()))
return;
err = NULL;
midx = mu_index_new (mu_runtime_xapian_dir(), 0, &err);
if (!midx) {