* mu-index.c, mu-maildir.c, test-mu-query.c: some refactoring to get max line

len <= 35
This commit is contained in:
Dirk-Jan C. Binnema 2010-02-02 08:46:01 +02:00
parent 64246329f5
commit 933245928f
3 changed files with 69 additions and 49 deletions

View File

@ -232,6 +232,27 @@ check_path (const char* path)
return TRUE;
}
static void
init_cb_data (MuIndexCallbackData *cb_data, MuStoreXapian *xapian,
gboolean reindex, MuIndexStats *stats,
MuIndexMsgCallback msg_cb, MuIndexDirCallback dir_cb,
void *user_data)
{
cb_data->_idx_msg_cb = msg_cb;
cb_data->_idx_dir_cb = dir_cb;
cb_data->_user_data = user_data;
cb_data->_xapian = xapian;
cb_data->_reindex = reindex;
cb_data->_dirstamp = 0;
cb_data->_stats = stats;
if (cb_data->_stats)
memset (cb_data->_stats, 0, sizeof(MuIndexStats));
}
MuResult
mu_index_run (MuIndex *index, const char* path,
@ -253,18 +274,8 @@ mu_index_run (MuIndex *index, const char* path,
return MU_ERROR;
}
if (stats)
memset (stats, 0, sizeof(MuIndexStats));
cb_data._idx_msg_cb = msg_cb;
cb_data._idx_dir_cb = dir_cb;
cb_data._user_data = user_data;
cb_data._xapian = index->_xapian;
cb_data._stats = stats;
cb_data._reindex = reindex;
cb_data._dirstamp = 0;
init_cb_data (&cb_data, index->_xapian, reindex, stats,
msg_cb, dir_cb, user_data);
rv = mu_maildir_walk (path,
(MuMaildirWalkMsgCallback)on_run_maildir_msg,

View File

@ -443,36 +443,22 @@ dirent_cmp (struct dirent *d1, struct dirent *d2)
}
#endif /*HAVE_STRUCT_DIRENT_D_INO*/
/* we sort the inodes if the FS's dirent has them. It makes
* file-access much faster on some filesystems, such as
* ext3,4. readdir_with_stat_fallback is a wrapper for readdir
* that falls back to (slow) stats if the FS does not support
* entry->d_type
*/
static MuResult
process_dir (const char* path, MuMaildirWalkMsgCallback msg_cb,
MuMaildirWalkDirCallback dir_cb, void *data)
process_dir_entries_sorted (DIR *dir, const char* path,
MuMaildirWalkMsgCallback msg_cb,
MuMaildirWalkDirCallback dir_cb, void *data)
{
MuResult result;
GList *lst, *c;
struct dirent *entry;
DIR* dir;
dir = opendir (path);
if (G_UNLIKELY(!dir)) {
g_warning ("%s: ignoring %s: %s", path,
__FUNCTION__, strerror(errno));
return MU_OK;
}
if (dir_cb) {
MuResult rv = dir_cb (path, TRUE, data);
if (rv != MU_OK) {
closedir (dir);
return rv;
}
}
/* we sort the inodes if the FS's dirent has them. It makes
* file-access much faster on some filesystems, such as
* ext3,4. readdir_with_stat_fallback is a wrapper for readdir
* that falls back to (slow) stats if the FS does not support
* entry->d_type
*/
lst = NULL;
while ((entry = readdir_with_stat_fallback (dir, path)))
lst = g_list_prepend (lst, dirent_copy(entry));
@ -492,6 +478,35 @@ process_dir (const char* path, MuMaildirWalkMsgCallback msg_cb,
g_list_foreach (lst, (GFunc)dirent_destroy, NULL);
g_list_free (lst);
return result;
}
static MuResult
process_dir (const char* path, MuMaildirWalkMsgCallback msg_cb,
MuMaildirWalkDirCallback dir_cb, void *data)
{
MuResult result;
DIR* dir;
dir = opendir (path);
if (G_UNLIKELY(!dir)) {
g_warning ("%s: ignoring %s: %s", path,
__FUNCTION__, strerror(errno));
return MU_OK;
}
if (dir_cb) {
MuResult rv = dir_cb (path, TRUE, data);
if (rv != MU_OK) {
closedir (dir);
return rv;
}
}
result = process_dir_entries_sorted (dir, path, msg_cb, dir_cb,
data);
closedir (dir);
if (dir_cb)

View File

@ -92,8 +92,6 @@ test_mu_query_01 (void)
{ "p:cur", 6 },
{ "path:new", 4 }
};
xpath = fill_database ();
g_assert (xpath != NULL);
@ -101,18 +99,14 @@ test_mu_query_01 (void)
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
int count;
MuMsgIterXapian *iter;
iter = mu_query_xapian_run (query, queries[i].query, NULL, FALSE, 1);
int count = 0;
MuMsgIterXapian *iter =
mu_query_xapian_run (query, queries[i].query, NULL,
FALSE, 1);
count = 0;
if (!mu_msg_iter_xapian_is_null (iter)) {
do {
++count;
} while (mu_msg_iter_xapian_next (iter));
}
if (!mu_msg_iter_xapian_is_null (iter))
do { ++count; } while (mu_msg_iter_xapian_next (iter));
g_assert_cmpuint (queries[i].count, ==, count);
mu_msg_iter_xapian_destroy (iter);
}