mirror of https://github.com/djcb/mu.git
* mu-index: improve cleanup (still WIP), improve documentation; add mu_index_clear_stats
This commit is contained in:
parent
d8dba2bb2c
commit
bc03af4b32
|
@ -31,6 +31,7 @@
|
|||
#include "mu-maildir.h"
|
||||
#include "mu-index.h"
|
||||
#include "mu-store-xapian.h"
|
||||
#include "mu-util.h"
|
||||
|
||||
#define MU_XAPIAN_DIR_NAME "xapian"
|
||||
|
||||
|
@ -47,6 +48,11 @@ mu_index_new (const char *muhome)
|
|||
char *xpath;
|
||||
|
||||
g_return_val_if_fail (muhome, NULL);
|
||||
|
||||
if (!mu_util_create_dir_maybe(muhome)) {
|
||||
g_warning ("Failed to create %s", muhome);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
index = g_new0 (MuIndex, 1);
|
||||
xpath = g_strdup_printf ("%s%c%s", muhome,
|
||||
|
@ -189,7 +195,7 @@ on_run_maildir_dir (const char* fullpath, gboolean enter,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
check_path (const char* path)
|
||||
_check_path (const char* path)
|
||||
{
|
||||
g_return_val_if_fail (path, FALSE);
|
||||
|
||||
|
@ -212,7 +218,9 @@ mu_index_run (MuIndex *index, const char* path,
|
|||
MuIndexCallbackData cb_data;
|
||||
|
||||
g_return_val_if_fail (index && index->_xapian, MU_ERROR);
|
||||
g_return_val_if_fail (check_path (path), MU_ERROR);
|
||||
|
||||
if (!_check_path (path))
|
||||
return MU_ERROR;
|
||||
|
||||
if (stats)
|
||||
memset (stats, 0, sizeof(MuIndexStats));
|
||||
|
@ -263,7 +271,9 @@ mu_index_stats (MuIndex *index, const char* path,
|
|||
MuIndexCallbackData cb_data;
|
||||
|
||||
g_return_val_if_fail (index, MU_ERROR);
|
||||
g_return_val_if_fail (check_path (path), MU_ERROR);
|
||||
|
||||
if (!_check_path (path))
|
||||
return MU_ERROR;
|
||||
|
||||
if (stats)
|
||||
memset (stats, 0, sizeof(MuIndexStats));
|
||||
|
@ -299,9 +309,13 @@ _foreach_doc_cb (const char* path, CleanupData *cudata)
|
|||
g_message ("not readable: %s; removing",
|
||||
path);
|
||||
/* FIXME: delete from db */
|
||||
++cudata->_stats->_cleaned_up;
|
||||
if (cudata->_stats)
|
||||
++cudata->_stats->_cleaned_up;
|
||||
}
|
||||
|
||||
if (cudata->_stats)
|
||||
++cudata->_stats->_processed;
|
||||
|
||||
if (!cudata->_cb)
|
||||
return MU_OK;
|
||||
|
||||
|
@ -329,3 +343,14 @@ mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
|||
&cudata);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
mu_index_stats_clear (MuIndexStats *stats)
|
||||
{
|
||||
if (!stats)
|
||||
return FALSE;
|
||||
|
||||
memset (stats, 0, sizeof(MuIndexStats));
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -89,7 +89,10 @@ typedef MuResult (*MuIndexDirCallback) (const char* path, gboolean enter,
|
|||
* @param path the path to index
|
||||
* @param force if != 0, force re-indexing already index messages; this is
|
||||
* obviously a lot slower than only indexing new/changed messages
|
||||
* @param result a structure with some statistics about the results
|
||||
* @param stats a structure with some statistics about the results;
|
||||
* note that this function does *not* reset the struct values to allow
|
||||
* for cumulative stats from multiple calls. If needed, you can use
|
||||
* @mu_index_stats_clear before calling this function
|
||||
* @param cb_msg a callback function called for every msg indexed;
|
||||
* @param cb_dir a callback function called for every dir entered/left;
|
||||
* @param user_data a user pointer that will be passed to the callback function
|
||||
|
@ -99,7 +102,7 @@ typedef MuResult (*MuIndexDirCallback) (const char* path, gboolean enter,
|
|||
* case of some error.
|
||||
*/
|
||||
MuResult mu_index_run (MuIndex *index, const char* path, gboolean force,
|
||||
MuIndexStats *result, MuIndexMsgCallback msg_cb,
|
||||
MuIndexStats *stats, MuIndexMsgCallback msg_cb,
|
||||
MuIndexDirCallback dir_cb, void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -110,7 +113,10 @@ MuResult mu_index_run (MuIndex *index, const char* path, gboolean force,
|
|||
*
|
||||
* @param index a valid MuIndex instance
|
||||
* @param path the path to get stats for
|
||||
* @param result a structure with some statistics about the results
|
||||
* @param stats a structure with some statistics about the results;
|
||||
* note that this function does *not* reset the struct values to allow
|
||||
* for cumulative stats from multiple calls. If needed, you can use
|
||||
* @mu_index_stats_clear before calling this function
|
||||
* @param cb a callback function which will be called for every msg;
|
||||
* @param user_data a user pointer that will be passed to the callback function
|
||||
* xb
|
||||
|
@ -118,7 +124,7 @@ MuResult mu_index_run (MuIndex *index, const char* path, gboolean force,
|
|||
* MU_STOP if the user stopped or MU_ERROR in
|
||||
* case of some error.
|
||||
*/
|
||||
MuResult mu_index_stats (MuIndex *index, const char* path, MuIndexStats *result,
|
||||
MuResult mu_index_stats (MuIndex *index, const char* path, MuIndexStats *stats,
|
||||
MuIndexMsgCallback msg_cb, MuIndexDirCallback dir_cb,
|
||||
void *user_data);
|
||||
|
||||
|
@ -133,14 +139,18 @@ MuResult mu_index_stats (MuIndex *index, const char* path, MuIndexStats *result,
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
typedef MuResult (*MuIndexCleanupDeleteCallback) (MuIndexStats*, void *user_data);
|
||||
typedef MuResult (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* cleanup the database; ie. remove entries for which no longer a corresponding
|
||||
* file exists in the maildir
|
||||
*
|
||||
* @param index a valid MuIndex instance
|
||||
* @param result a structure with some statistics about the results
|
||||
* @param stats a structure with some statistics about the results;
|
||||
* note that this function does *not* reset the struct values to allow
|
||||
* for cumulative stats from multiple calls. If needed, you can use
|
||||
* @mu_index_stats_clear before calling this function
|
||||
* @param cb a callback function which will be called for every msg;
|
||||
* @param user_data a user pointer that will be passed to the callback function
|
||||
*
|
||||
|
@ -148,8 +158,17 @@ typedef MuResult (*MuIndexCleanupDeleteCallback) (MuIndexStats*, void *user_data
|
|||
* MU_STOP if the user stopped or MU_ERROR in
|
||||
* case of some error.
|
||||
*/
|
||||
MuResult mu_index_cleanup (MuIndex *index, MuIndexStats *result,
|
||||
MuResult mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
||||
MuIndexCleanupDeleteCallback cb,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* clear the stats structure
|
||||
*
|
||||
* @param stats a MuIndexStats object
|
||||
*
|
||||
* @return TRUE if stats != NULL, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_index_stats_clear (MuIndexStats *stats);
|
||||
|
||||
#endif /*__MU_INDEX_H__*/
|
||||
|
|
Loading…
Reference in New Issue