* mu-index: update for the store changes
This commit is contained in:
@ -42,7 +42,6 @@
|
|||||||
struct _MuIndex {
|
struct _MuIndex {
|
||||||
MuStore *_store;
|
MuStore *_store;
|
||||||
gboolean _needs_reindex;
|
gboolean _needs_reindex;
|
||||||
gchar *_last_used_maildir;
|
|
||||||
guint _max_filesize;
|
guint _max_filesize;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,6 +49,7 @@ MuIndex*
|
|||||||
mu_index_new (MuStore *store, GError **err)
|
mu_index_new (MuStore *store, GError **err)
|
||||||
{
|
{
|
||||||
MuIndex *index;
|
MuIndex *index;
|
||||||
|
unsigned count;
|
||||||
|
|
||||||
g_return_val_if_fail (store, NULL);
|
g_return_val_if_fail (store, NULL);
|
||||||
g_return_val_if_fail (!mu_store_is_read_only(store), NULL);
|
g_return_val_if_fail (!mu_store_is_read_only(store), NULL);
|
||||||
@ -61,7 +61,10 @@ mu_index_new (MuStore *store, GError **err)
|
|||||||
/* set the default max file size */
|
/* set the default max file size */
|
||||||
index->_max_filesize = MU_INDEX_MAX_FILE_SIZE;
|
index->_max_filesize = MU_INDEX_MAX_FILE_SIZE;
|
||||||
|
|
||||||
if (mu_store_count (store) == 0)
|
count = mu_store_count (store, err);
|
||||||
|
if (count == (unsigned)-1)
|
||||||
|
return NULL;
|
||||||
|
else if (count == 0)
|
||||||
index->_needs_reindex = FALSE;
|
index->_needs_reindex = FALSE;
|
||||||
|
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
@ -78,7 +81,6 @@ mu_index_destroy (MuIndex *index)
|
|||||||
if (!index)
|
if (!index)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_free (index->_last_used_maildir);
|
|
||||||
mu_store_unref (index->_store);
|
mu_store_unref (index->_store);
|
||||||
g_free (index);
|
g_free (index);
|
||||||
}
|
}
|
||||||
@ -109,8 +111,8 @@ needs_index (MuIndexCallbackData *data, const char *fullpath,
|
|||||||
if (data->_reindex)
|
if (data->_reindex)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* it's not in the database yet */
|
/* it's not in the database yet (FIXME: GError)*/
|
||||||
if (!mu_store_contains_message (data->_store, fullpath))
|
if (!mu_store_contains_message (data->_store, fullpath, NULL))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* it's there, but it's not up to date */
|
/* it's there, but it's not up to date */
|
||||||
@ -207,19 +209,23 @@ static MuError
|
|||||||
on_run_maildir_dir (const char* fullpath, gboolean enter,
|
on_run_maildir_dir (const char* fullpath, gboolean enter,
|
||||||
MuIndexCallbackData *data)
|
MuIndexCallbackData *data)
|
||||||
{
|
{
|
||||||
|
GError *err;
|
||||||
|
err = NULL;
|
||||||
|
|
||||||
/* xapian stores a per-dir timestamp; we use this timestamp
|
/* xapian stores a per-dir timestamp; we use this timestamp
|
||||||
* to determine whether a message is up-to-data
|
* to determine whether a message is up-to-data
|
||||||
*/
|
*/
|
||||||
if (enter) {
|
if (enter) {
|
||||||
data->_dirstamp =
|
data->_dirstamp =
|
||||||
mu_store_get_timestamp (data->_store,
|
mu_store_get_timestamp (data->_store, fullpath, &err);
|
||||||
fullpath);
|
|
||||||
g_debug ("entering %s (ts==%u)",
|
g_debug ("entering %s (ts==%u)",
|
||||||
fullpath, (unsigned)data->_dirstamp);
|
fullpath, (unsigned)data->_dirstamp);
|
||||||
} else {
|
} else {
|
||||||
time_t now = time (NULL);
|
time_t now;
|
||||||
|
now = time (NULL);
|
||||||
|
|
||||||
mu_store_set_timestamp (data->_store, fullpath,
|
mu_store_set_timestamp (data->_store, fullpath,
|
||||||
now);
|
now, &err);
|
||||||
g_debug ("leaving %s (ts=%u)",
|
g_debug ("leaving %s (ts=%u)",
|
||||||
fullpath, (unsigned)data->_dirstamp);
|
fullpath, (unsigned)data->_dirstamp);
|
||||||
}
|
}
|
||||||
@ -228,6 +234,11 @@ on_run_maildir_dir (const char* fullpath, gboolean enter,
|
|||||||
return data->_idx_dir_cb (fullpath, enter,
|
return data->_idx_dir_cb (fullpath, enter,
|
||||||
data->_user_data);
|
data->_user_data);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
MU_WRITE_LOG ("%s: %s", __FUNCTION__, err->message);
|
||||||
|
g_clear_error(&err);
|
||||||
|
}
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,25 +283,6 @@ init_cb_data (MuIndexCallbackData *cb_data, MuStore *xapian,
|
|||||||
memset (cb_data->_stats, 0, sizeof(MuIndexStats));
|
memset (cb_data->_stats, 0, sizeof(MuIndexStats));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_last_used_maildir (MuIndex *index, const char *path)
|
|
||||||
{
|
|
||||||
if (!mu_store_set_metadata (index->_store,
|
|
||||||
MU_LAST_USED_MAILDIR_KEY,
|
|
||||||
path))
|
|
||||||
g_warning ("%s: failed to set metadata", __FUNCTION__);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_index_last_used_maildir (MuIndex *index)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (index, NULL);
|
|
||||||
g_free (index->_last_used_maildir);
|
|
||||||
|
|
||||||
return index->_last_used_maildir =
|
|
||||||
mu_store_get_metadata (index->_store,
|
|
||||||
MU_LAST_USED_MAILDIR_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_index_set_max_msg_size (MuIndex *index, guint max_size)
|
mu_index_set_max_msg_size (MuIndex *index, guint max_size)
|
||||||
@ -337,8 +329,6 @@ mu_index_run (MuIndex *index, const char* path,
|
|||||||
index->_max_filesize, stats,
|
index->_max_filesize, stats,
|
||||||
msg_cb, dir_cb, user_data);
|
msg_cb, dir_cb, user_data);
|
||||||
|
|
||||||
update_last_used_maildir (index, path);
|
|
||||||
|
|
||||||
rv = mu_maildir_walk (path,
|
rv = mu_maildir_walk (path,
|
||||||
(MuMaildirWalkMsgCallback)on_run_maildir_msg,
|
(MuMaildirWalkMsgCallback)on_run_maildir_msg,
|
||||||
(MuMaildirWalkDirCallback)on_run_maildir_dir,
|
(MuMaildirWalkDirCallback)on_run_maildir_dir,
|
||||||
@ -436,7 +426,7 @@ foreach_doc_cb (const char* path, CleanupData *cudata)
|
|||||||
MuError
|
MuError
|
||||||
mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
||||||
MuIndexCleanupDeleteCallback cb,
|
MuIndexCleanupDeleteCallback cb,
|
||||||
void *user_data)
|
void *user_data, GError **err)
|
||||||
{
|
{
|
||||||
MuError rv;
|
MuError rv;
|
||||||
CleanupData cudata;
|
CleanupData cudata;
|
||||||
@ -451,7 +441,8 @@ mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
|||||||
|
|
||||||
rv = mu_store_foreach (index->_store,
|
rv = mu_store_foreach (index->_store,
|
||||||
(MuStoreForeachFunc)foreach_doc_cb,
|
(MuStoreForeachFunc)foreach_doc_cb,
|
||||||
&cudata);
|
&cudata, err);
|
||||||
|
|
||||||
mu_store_flush (index->_store);
|
mu_store_flush (index->_store);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
@ -87,17 +87,6 @@ void mu_index_set_max_msg_size (MuIndex *index, guint max_size);
|
|||||||
void mu_index_set_xbatch_size (MuIndex *index, guint xbatchsize);
|
void mu_index_set_xbatch_size (MuIndex *index, guint xbatchsize);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the maildir for the last run of indexing for the
|
|
||||||
* current database
|
|
||||||
*
|
|
||||||
* @param index MuIndex object
|
|
||||||
*
|
|
||||||
* @return the last used maildir, or NULL
|
|
||||||
*/
|
|
||||||
const char* mu_index_last_used_maildir (MuIndex *index);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* callback function for mu_index_(run|stats|cleanup), for each message
|
* callback function for mu_index_(run|stats|cleanup), for each message
|
||||||
*
|
*
|
||||||
@ -193,6 +182,7 @@ typedef MuError (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
|
|||||||
* @mu_index_stats_clear before calling this function
|
* @mu_index_stats_clear before calling this function
|
||||||
* @param cb a callback function which will be called for every msg;
|
* @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
|
* @param user_data a user pointer that will be passed to the callback function
|
||||||
|
* @param err to receive error info or NULL. err->code is MuError value
|
||||||
*
|
*
|
||||||
* @return MU_OK if the stats gathering was completed succesfully,
|
* @return MU_OK if the stats gathering was completed succesfully,
|
||||||
* MU_STOP if the user stopped or MU_ERROR in
|
* MU_STOP if the user stopped or MU_ERROR in
|
||||||
@ -200,7 +190,7 @@ typedef MuError (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
|
|||||||
*/
|
*/
|
||||||
MuError mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
MuError mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
||||||
MuIndexCleanupDeleteCallback cb,
|
MuIndexCleanupDeleteCallback cb,
|
||||||
void *user_data);
|
void *user_data, GError **err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clear the stats structure
|
* clear the stats structure
|
||||||
|
|||||||
Reference in New Issue
Block a user