mirror of https://github.com/djcb/mu.git
* mu-index.c, mu-maildir.c, test-mu-query.c: some refactoring to get max line
len <= 35
This commit is contained in:
parent
64246329f5
commit
933245928f
|
@ -232,6 +232,27 @@ check_path (const char* path)
|
||||||
return TRUE;
|
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
|
MuResult
|
||||||
mu_index_run (MuIndex *index, const char* path,
|
mu_index_run (MuIndex *index, const char* path,
|
||||||
|
@ -253,18 +274,8 @@ mu_index_run (MuIndex *index, const char* path,
|
||||||
return MU_ERROR;
|
return MU_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats)
|
init_cb_data (&cb_data, index->_xapian, reindex, stats,
|
||||||
memset (stats, 0, sizeof(MuIndexStats));
|
msg_cb, dir_cb, 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 = index->_xapian;
|
|
||||||
cb_data._stats = stats;
|
|
||||||
|
|
||||||
cb_data._reindex = reindex;
|
|
||||||
cb_data._dirstamp = 0;
|
|
||||||
|
|
||||||
rv = mu_maildir_walk (path,
|
rv = mu_maildir_walk (path,
|
||||||
(MuMaildirWalkMsgCallback)on_run_maildir_msg,
|
(MuMaildirWalkMsgCallback)on_run_maildir_msg,
|
||||||
|
|
|
@ -443,36 +443,22 @@ dirent_cmp (struct dirent *d1, struct dirent *d2)
|
||||||
}
|
}
|
||||||
#endif /*HAVE_STRUCT_DIRENT_D_INO*/
|
#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
|
static MuResult
|
||||||
process_dir (const char* path, MuMaildirWalkMsgCallback msg_cb,
|
process_dir_entries_sorted (DIR *dir, const char* path,
|
||||||
MuMaildirWalkDirCallback dir_cb, void *data)
|
MuMaildirWalkMsgCallback msg_cb,
|
||||||
|
MuMaildirWalkDirCallback dir_cb, void *data)
|
||||||
{
|
{
|
||||||
MuResult result;
|
MuResult result;
|
||||||
GList *lst, *c;
|
GList *lst, *c;
|
||||||
struct dirent *entry;
|
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;
|
lst = NULL;
|
||||||
while ((entry = readdir_with_stat_fallback (dir, path)))
|
while ((entry = readdir_with_stat_fallback (dir, path)))
|
||||||
lst = g_list_prepend (lst, dirent_copy(entry));
|
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_foreach (lst, (GFunc)dirent_destroy, NULL);
|
||||||
g_list_free (lst);
|
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);
|
closedir (dir);
|
||||||
|
|
||||||
if (dir_cb)
|
if (dir_cb)
|
||||||
|
|
|
@ -92,8 +92,6 @@ test_mu_query_01 (void)
|
||||||
{ "p:cur", 6 },
|
{ "p:cur", 6 },
|
||||||
{ "path:new", 4 }
|
{ "path:new", 4 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
xpath = fill_database ();
|
xpath = fill_database ();
|
||||||
g_assert (xpath != NULL);
|
g_assert (xpath != NULL);
|
||||||
|
|
||||||
|
@ -101,18 +99,14 @@ test_mu_query_01 (void)
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
|
|
||||||
int count;
|
int count = 0;
|
||||||
MuMsgIterXapian *iter;
|
MuMsgIterXapian *iter =
|
||||||
|
mu_query_xapian_run (query, queries[i].query, NULL,
|
||||||
iter = mu_query_xapian_run (query, queries[i].query, NULL, FALSE, 1);
|
FALSE, 1);
|
||||||
|
|
||||||
count = 0;
|
if (!mu_msg_iter_xapian_is_null (iter))
|
||||||
if (!mu_msg_iter_xapian_is_null (iter)) {
|
do { ++count; } while (mu_msg_iter_xapian_next (iter));
|
||||||
do {
|
|
||||||
++count;
|
|
||||||
} while (mu_msg_iter_xapian_next (iter));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_cmpuint (queries[i].count, ==, count);
|
g_assert_cmpuint (queries[i].count, ==, count);
|
||||||
mu_msg_iter_xapian_destroy (iter);
|
mu_msg_iter_xapian_destroy (iter);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue