* remember last-used maildir, and use it as default for next run
This commit is contained in:
@ -34,9 +34,12 @@
|
||||
#include "mu-store.h"
|
||||
#include "mu-util.h"
|
||||
|
||||
#define MU_LAST_USED_MAILDIR_KEY "last_used_maildir"
|
||||
|
||||
struct _MuIndex {
|
||||
MuStore *_xapian;
|
||||
MuStore *_store;
|
||||
gboolean _needs_reindex;
|
||||
gchar *_last_used_maildir;
|
||||
};
|
||||
|
||||
MuIndex*
|
||||
@ -47,9 +50,9 @@ mu_index_new (const char *xpath, guint xbatchsize, GError **err)
|
||||
g_return_val_if_fail (xpath, NULL);
|
||||
|
||||
index = g_new0 (MuIndex, 1);
|
||||
index->_xapian = mu_store_new (xpath, xbatchsize, err);
|
||||
|
||||
if (!index->_xapian) {
|
||||
|
||||
index->_store = mu_store_new (xpath, xbatchsize, err);
|
||||
if (!index->_store) {
|
||||
g_warning ("%s: failed to open xapian store (%s)",
|
||||
__FUNCTION__, xpath);
|
||||
g_free (index);
|
||||
@ -60,11 +63,11 @@ mu_index_new (const char *xpath, guint xbatchsize, GError **err)
|
||||
* race-condition here, between mu_index_new and
|
||||
* mu_index_run. Maybe do the check in mu_index_run
|
||||
* instead? */
|
||||
if (mu_util_db_is_empty (xpath))
|
||||
if (mu_util_xapian_is_empty (xpath))
|
||||
index->_needs_reindex = FALSE;
|
||||
else
|
||||
index->_needs_reindex =
|
||||
mu_util_db_version_up_to_date (xpath) ? FALSE : TRUE;
|
||||
mu_util_xapian_needs_upgrade (xpath);
|
||||
|
||||
return index;
|
||||
}
|
||||
@ -75,8 +78,10 @@ mu_index_destroy (MuIndex *index)
|
||||
{
|
||||
if (!index)
|
||||
return;
|
||||
|
||||
mu_store_destroy (index->_xapian);
|
||||
|
||||
g_free (index->_last_used_maildir);
|
||||
mu_store_destroy (index->_store);
|
||||
|
||||
g_free (index);
|
||||
}
|
||||
|
||||
@ -84,7 +89,7 @@ mu_index_destroy (MuIndex *index)
|
||||
struct _MuIndexCallbackData {
|
||||
MuIndexMsgCallback _idx_msg_cb;
|
||||
MuIndexDirCallback _idx_dir_cb;
|
||||
MuStore* _xapian;
|
||||
MuStore* _store;
|
||||
void* _user_data;
|
||||
MuIndexStats* _stats;
|
||||
gboolean _reindex;
|
||||
@ -107,7 +112,7 @@ needs_index (MuIndexCallbackData *data, const char *fullpath,
|
||||
return TRUE;
|
||||
|
||||
/* it's not in the database yet */
|
||||
if (!mu_store_contains_message (data->_xapian, fullpath))
|
||||
if (!mu_store_contains_message (data->_store, fullpath))
|
||||
return TRUE;
|
||||
|
||||
/* it's there, but it's not up to date */
|
||||
@ -139,7 +144,7 @@ insert_or_update_maybe (const char* fullpath, const char* mdir,
|
||||
}
|
||||
|
||||
/* we got a valid id; scan the message contents as well */
|
||||
if (G_UNLIKELY((mu_store_store (data->_xapian, msg) != MU_OK))) {
|
||||
if (G_UNLIKELY((mu_store_store (data->_store, msg) != MU_OK))) {
|
||||
g_warning ("%s: storing content %s failed", __FUNCTION__,
|
||||
fullpath);
|
||||
return MU_ERROR;
|
||||
@ -206,13 +211,13 @@ on_run_maildir_dir (const char* fullpath, gboolean enter,
|
||||
*/
|
||||
if (enter) {
|
||||
data->_dirstamp =
|
||||
mu_store_get_timestamp (data->_xapian,
|
||||
mu_store_get_timestamp (data->_store,
|
||||
fullpath);
|
||||
g_debug ("entering %s (ts==%u)",
|
||||
fullpath, (unsigned)data->_dirstamp);
|
||||
} else {
|
||||
time_t now = time (NULL);
|
||||
mu_store_set_timestamp (data->_xapian, fullpath,
|
||||
mu_store_set_timestamp (data->_store, fullpath,
|
||||
now);
|
||||
g_debug ("leaving %s (ts=%u)",
|
||||
fullpath, (unsigned)data->_dirstamp);
|
||||
@ -255,7 +260,7 @@ init_cb_data (MuIndexCallbackData *cb_data, MuStore *xapian,
|
||||
cb_data->_idx_dir_cb = dir_cb;
|
||||
|
||||
cb_data->_user_data = user_data;
|
||||
cb_data->_xapian = xapian;
|
||||
cb_data->_store = xapian;
|
||||
|
||||
cb_data->_reindex = reindex;
|
||||
cb_data->_dirstamp = 0;
|
||||
@ -265,6 +270,25 @@ init_cb_data (MuIndexCallbackData *cb_data, MuStore *xapian,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
MuResult
|
||||
@ -276,7 +300,7 @@ mu_index_run (MuIndex *index, const char* path,
|
||||
MuIndexCallbackData cb_data;
|
||||
MuResult rv;
|
||||
|
||||
g_return_val_if_fail (index && index->_xapian, MU_ERROR);
|
||||
g_return_val_if_fail (index && index->_store, MU_ERROR);
|
||||
g_return_val_if_fail (msg_cb, MU_ERROR);
|
||||
|
||||
if (!check_path (path))
|
||||
@ -287,15 +311,17 @@ mu_index_run (MuIndex *index, const char* path,
|
||||
return MU_ERROR;
|
||||
}
|
||||
|
||||
init_cb_data (&cb_data, index->_xapian, reindex, stats,
|
||||
init_cb_data (&cb_data, index->_store, reindex, stats,
|
||||
msg_cb, dir_cb, user_data);
|
||||
|
||||
update_last_used_maildir (index, path);
|
||||
|
||||
rv = mu_maildir_walk (path,
|
||||
(MuMaildirWalkMsgCallback)on_run_maildir_msg,
|
||||
(MuMaildirWalkDirCallback)on_run_maildir_dir,
|
||||
&cb_data);
|
||||
|
||||
mu_store_flush (index->_xapian);
|
||||
mu_store_flush (index->_store);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -354,7 +380,7 @@ mu_index_stats (MuIndex *index, const char* path,
|
||||
|
||||
|
||||
struct _CleanupData {
|
||||
MuStore *_xapian;
|
||||
MuStore *_store;
|
||||
MuIndexStats *_stats;
|
||||
MuIndexCleanupDeleteCallback _cb;
|
||||
void *_user_data;
|
||||
@ -371,7 +397,7 @@ foreach_doc_cb (const char* path, CleanupData *cudata)
|
||||
if (access (path, R_OK) != 0) {
|
||||
|
||||
g_debug ("not readable: %s; removing", path);
|
||||
rv = mu_store_remove (cudata->_xapian, path);
|
||||
rv = mu_store_remove (cudata->_store, path);
|
||||
if (rv != MU_OK)
|
||||
return rv; /* something went wrong... bail out */
|
||||
|
||||
@ -400,15 +426,15 @@ mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
||||
g_return_val_if_fail (index, MU_ERROR);
|
||||
g_return_val_if_fail (cb, MU_ERROR);
|
||||
|
||||
cudata._xapian = index->_xapian;
|
||||
cudata._store = index->_store;
|
||||
cudata._stats = stats;
|
||||
cudata._cb = cb;
|
||||
cudata._user_data = user_data;
|
||||
|
||||
rv = mu_store_foreach (index->_xapian,
|
||||
rv = mu_store_foreach (index->_store,
|
||||
(MuStoreForeachFunc)foreach_doc_cb,
|
||||
&cudata);
|
||||
mu_store_flush (index->_xapian);
|
||||
mu_store_flush (index->_store);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user