* rename MuStoreXapian => MuStore

This commit is contained in:
djcb 2010-08-25 21:55:08 +03:00
parent 0c04143bbc
commit 2cd082c06b
4 changed files with 80 additions and 80 deletions

View File

@ -83,8 +83,8 @@ libmu_la_SOURCES= \
mu-query.cc \
mu-query.h \
mu-result.h \
mu-store-xapian.cc \
mu-store-xapian.h \
mu-store.cc \
mu-store.h \
mu-util-db.cc \
mu-util-db.h \
mu-util.c \

View File

@ -28,12 +28,12 @@
#include "mu-maildir.h"
#include "mu-index.h"
#include "mu-store-xapian.h"
#include "mu-store.h"
#include "mu-util.h"
#include "mu-util-db.h"
struct _MuIndex {
MuStoreXapian *_xapian;
MuStore *_xapian;
gboolean _needs_reindex;
};
@ -45,7 +45,7 @@ mu_index_new (const char *xpath)
g_return_val_if_fail (xpath, NULL);
index = g_new0 (MuIndex, 1);
index->_xapian = mu_store_xapian_new (xpath);
index->_xapian = mu_store_new (xpath);
if (!index->_xapian) {
g_warning ("%s: failed to open xapian store (%s)",
@ -74,7 +74,7 @@ mu_index_destroy (MuIndex *index)
if (!index)
return;
mu_store_xapian_destroy (index->_xapian);
mu_store_destroy (index->_xapian);
g_free (index);
}
@ -83,7 +83,7 @@ mu_index_destroy (MuIndex *index)
struct _MuIndexCallbackData {
MuIndexMsgCallback _idx_msg_cb;
MuIndexDirCallback _idx_dir_cb;
MuStoreXapian* _xapian;
MuStore* _xapian;
void* _user_data;
MuIndexStats* _stats;
gboolean _reindex;
@ -133,7 +133,7 @@ insert_or_update_maybe (const char* fullpath, const char* mdir,
}
/* we got a valid id; scan the message contents as well */
if (mu_store_xapian_store (data->_xapian, msg) != MU_OK) {
if (mu_store_store (data->_xapian, msg) != MU_OK) {
g_warning ("%s: storing content %s failed", __FUNCTION__,
fullpath);
/* ignore...*/
@ -200,13 +200,13 @@ on_run_maildir_dir (const char* fullpath, gboolean enter,
*/
if (enter) {
data->_dirstamp =
mu_store_xapian_get_timestamp (data->_xapian,
mu_store_get_timestamp (data->_xapian,
fullpath);
g_debug ("entering %s (ts==%u)",
fullpath, (unsigned)data->_dirstamp);
} else {
time_t now = time (NULL);
mu_store_xapian_set_timestamp (data->_xapian, fullpath,
mu_store_set_timestamp (data->_xapian, fullpath,
now);
g_debug ("leaving %s (ts=%u)",
fullpath, (unsigned)data->_dirstamp);
@ -240,7 +240,7 @@ check_path (const char* path)
}
static void
init_cb_data (MuIndexCallbackData *cb_data, MuStoreXapian *xapian,
init_cb_data (MuIndexCallbackData *cb_data, MuStore *xapian,
gboolean reindex, MuIndexStats *stats,
MuIndexMsgCallback msg_cb, MuIndexDirCallback dir_cb,
void *user_data)
@ -289,12 +289,12 @@ mu_index_run (MuIndex *index, const char* path,
(MuMaildirWalkDirCallback)on_run_maildir_dir,
&cb_data);
if (rv == MU_OK) {
if (!mu_store_xapian_set_version (index->_xapian,
if (!mu_store_set_version (index->_xapian,
MU_XAPIAN_DB_VERSION))
g_warning ("failed to set database version");
}
mu_store_xapian_flush (index->_xapian);
mu_store_flush (index->_xapian);
return rv;
}
@ -352,7 +352,7 @@ mu_index_stats (MuIndex *index, const char* path,
struct _CleanupData {
MuStoreXapian *_xapian;
MuStore *_xapian;
MuIndexStats *_stats;
MuIndexCleanupDeleteCallback _cb;
void *_user_data;
@ -369,7 +369,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_xapian_remove (cudata->_xapian, path);
rv = mu_store_remove (cudata->_xapian, path);
if (rv != MU_OK)
return rv; /* something went wrong... bail out */
@ -403,10 +403,10 @@ mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
cudata._cb = cb;
cudata._user_data = user_data;
rv = mu_store_xapian_foreach (index->_xapian,
(MuStoreXapianForeachFunc)foreach_doc_cb,
rv = mu_store_foreach (index->_xapian,
(MuStoreForeachFunc)foreach_doc_cb,
&cudata);
mu_store_xapian_flush (index->_xapian);
mu_store_flush (index->_xapian);
return rv;
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -25,16 +25,16 @@
#include <xapian.h>
#include "mu-msg.h"
#include "mu-store-xapian.h"
#include "mu-store.h"
#include "mu-util.h"
/* number of new messages after which we commit to the database */
#define MU_STORE_XAPIAN_TRX_SIZE 2000
#define MU_STORE_TRX_SIZE 2000
/* http://article.gmane.org/gmane.comp.search.xapian.general/3656 */
#define MU_STORE_XAPIAN_MAX_TERM_LENGTH 240
#define MU_STORE_MAX_TERM_LENGTH 240
struct _MuStoreXapian {
struct _MuStore {
Xapian::WritableDatabase *_db;
/* transaction handling */
@ -43,20 +43,20 @@ struct _MuStoreXapian {
size_t _trx_size;
};
MuStoreXapian*
mu_store_xapian_new (const char* xpath)
MuStore*
mu_store_new (const char* xpath)
{
MuStoreXapian *store (0);
MuStore *store (0);
g_return_val_if_fail (xpath, NULL);
try {
store = g_new0(MuStoreXapian,1);
store = g_new0(MuStore,1);
store->_db = new Xapian::WritableDatabase
(xpath, Xapian::DB_CREATE_OR_OPEN);
/* keep count of processed docs */
store->_trx_size = MU_STORE_XAPIAN_TRX_SIZE;
store->_trx_size = MU_STORE_TRX_SIZE;
store->_in_transaction = false;
store->_processed = 0;
@ -74,7 +74,7 @@ mu_store_xapian_new (const char* xpath)
char*
mu_store_xapian_version (MuStoreXapian *store)
mu_store_version (MuStore *store)
{
g_return_val_if_fail (store, NULL);
@ -90,7 +90,7 @@ mu_store_xapian_version (MuStoreXapian *store)
}
gboolean
mu_store_xapian_set_version (MuStoreXapian *store, const char* version)
mu_store_set_version (MuStore *store, const char* version)
{
g_return_val_if_fail (store, FALSE);
g_return_val_if_fail (version, FALSE);
@ -106,7 +106,7 @@ mu_store_xapian_set_version (MuStoreXapian *store, const char* version)
static void
begin_trx_if (MuStoreXapian *store, gboolean cond)
begin_trx_if (MuStore *store, gboolean cond)
{
if (cond) {
g_debug ("beginning Xapian transaction");
@ -116,7 +116,7 @@ begin_trx_if (MuStoreXapian *store, gboolean cond)
}
static void
commit_trx_if (MuStoreXapian *store, gboolean cond)
commit_trx_if (MuStore *store, gboolean cond)
{
if (cond) {
g_debug ("comitting Xapian transaction");
@ -126,7 +126,7 @@ commit_trx_if (MuStoreXapian *store, gboolean cond)
}
static void
rollback_trx_if (MuStoreXapian *store, gboolean cond)
rollback_trx_if (MuStore *store, gboolean cond)
{
if (cond) {
g_debug ("rolling back Xapian transaction");
@ -137,13 +137,13 @@ rollback_trx_if (MuStoreXapian *store, gboolean cond)
void
mu_store_xapian_destroy (MuStoreXapian *store)
mu_store_destroy (MuStore *store)
{
if (!store)
return;
try {
mu_store_xapian_flush (store);
mu_store_flush (store);
MU_WRITE_LOG ("closing xapian database with %d documents",
(int)store->_db->get_doccount());
@ -155,7 +155,7 @@ mu_store_xapian_destroy (MuStoreXapian *store)
}
void
mu_store_xapian_flush (MuStoreXapian *store)
mu_store_flush (MuStore *store)
{
g_return_if_fail (store);
@ -200,11 +200,11 @@ add_terms_values_string (Xapian::Document& doc, MuMsg *msg,
}
if (mu_msg_field_xapian_term(field))
/* terms can be up to MU_STORE_XAPIAN_MAX_TERM_LENGTH
/* terms can be up to MU_STORE_MAX_TERM_LENGTH
* (240) long; this is a Xapian limit
* */
doc.add_term (std::string (prefix + value, 0,
MU_STORE_XAPIAN_MAX_TERM_LENGTH));
MU_STORE_MAX_TERM_LENGTH));
if (mu_msg_field_xapian_value(field))
doc.add_value ((Xapian::valueno)mu_msg_field_id (field),
@ -291,7 +291,7 @@ get_message_uid (MuMsg *msg)
MuResult
mu_store_xapian_store (MuStoreXapian *store, MuMsg *msg)
mu_store_store (MuStore *store, MuMsg *msg)
{
g_return_val_if_fail (store, MU_ERROR);
g_return_val_if_fail (msg, MU_ERROR);
@ -326,7 +326,7 @@ mu_store_xapian_store (MuStoreXapian *store, MuMsg *msg)
MuResult
mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath)
mu_store_remove (MuStore *store, const char* msgpath)
{
g_return_val_if_fail (store, MU_ERROR);
g_return_val_if_fail (msgpath, MU_ERROR);
@ -352,7 +352,7 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath)
}
gboolean
mu_store_contains_message (MuStoreXapian *store, const char* path)
mu_store_contains_message (MuStore *store, const char* path)
{
g_return_val_if_fail (store, NULL);
g_return_val_if_fail (path, NULL);
@ -367,7 +367,7 @@ mu_store_contains_message (MuStoreXapian *store, const char* path)
time_t
mu_store_xapian_get_timestamp (MuStoreXapian *store, const char* msgpath)
mu_store_get_timestamp (MuStore *store, const char* msgpath)
{
g_return_val_if_fail (store, 0);
g_return_val_if_fail (msgpath, 0);
@ -386,8 +386,8 @@ mu_store_xapian_get_timestamp (MuStoreXapian *store, const char* msgpath)
void
mu_store_xapian_set_timestamp (MuStoreXapian *store, const char* msgpath,
time_t stamp)
mu_store_set_timestamp (MuStore *store, const char* msgpath,
time_t stamp)
{
g_return_if_fail (store);
g_return_if_fail (msgpath);
@ -402,8 +402,8 @@ mu_store_xapian_set_timestamp (MuStoreXapian *store, const char* msgpath,
MuResult
mu_store_xapian_foreach (MuStoreXapian *self,
MuStoreXapianForeachFunc func, void *user_data)
mu_store_foreach (MuStore *self,
MuStoreForeachFunc func, void *user_data)
{
g_return_val_if_fail (self, MU_ERROR);
g_return_val_if_fail (func, MU_ERROR);

View File

@ -17,8 +17,8 @@
**
*/
#ifndef __MU_STORE_XAPIAN_H__
#define __MU_STORE_XAPIAN_H__
#ifndef __MU_STORE_H__
#define __MU_STORE_H__
#include <glib.h>
#include <inttypes.h>
@ -28,56 +28,56 @@
G_BEGIN_DECLS
struct _MuStoreXapian;
typedef struct _MuStoreXapian MuStoreXapian;
struct _MuStore;
typedef struct _MuStore MuStore;
/**
/**
* create a new Xapian store, a place to store documents
*
* @param path the path to the database
*
* @return a new MuStoreXapian object, or NULL in case of error
* @return a new MuStore object, or NULL in case of error
*/
MuStoreXapian* mu_store_xapian_new (const char* path);
MuStore* mu_store_new (const char* path);
/**
* destroy the MuStoreXapian object and free resources
/**
* destroy the MuStore object and free resources
*
* @param store a valid store, or NULL
*/
void mu_store_xapian_destroy (MuStoreXapian *store);
void mu_store_destroy (MuStore *store);
/**
/**
* get a version string for the database
*
* @param store a valid MuStoreXapian
* @param store a valid MuStore
*
* @return the version string (free with g_free), or NULL in case of error
*/
char* mu_store_xapian_version (MuStoreXapian *store);
char* mu_store_version (MuStore *store);
/**
/**
* set the version string for the database
*
* @param store a valid MuStoreXapian
* @param store a valid MuStore
* @param version the version string (non-NULL)
*
* @return TRUE if setting the version succeeded, FALSE otherwise
*/
gboolean mu_store_xapian_set_version (MuStoreXapian *store,
gboolean mu_store_set_version (MuStore *store,
const char* version);
/**
/**
* try to flush/commit all outstanding work
*
* @param store a valid xapian store
*/
void mu_store_xapian_flush (MuStoreXapian *store);
void mu_store_flush (MuStore *store);
/**
/**
* store an email message in the XapianStore
*
* @param store a valid store
@ -85,10 +85,10 @@ void mu_store_xapian_flush (MuStoreXapian *store);
*
* @return TRUE if it succeeded, FALSE otherwise
*/
MuResult mu_store_xapian_store (MuStoreXapian *store, MuMsg *msg);
MuResult mu_store_store (MuStore *store, MuMsg *msg);
/**
/**
* remove a message from the database
*
* @param store a valid store
@ -99,11 +99,11 @@ MuResult mu_store_xapian_store (MuStoreXapian *store, MuMsg *msg);
*
* @return TRUE if it succeeded, FALSE otherwise
*/
MuResult mu_store_xapian_remove (MuStoreXapian *store,
MuResult mu_store_remove (MuStore *store,
const char* msgpath);
/**
/**
* does a certain message exist in the database already?
*
* @param store a store
@ -111,21 +111,21 @@ MuResult mu_store_xapian_remove (MuStoreXapian *store,
*
* @return
*/
gboolean mu_store_contains_message (MuStoreXapian *store,
gboolean mu_store_contains_message (MuStore *store,
const char* path);
/**
/**
* store a timestamp for a directory
*
* @param store a valid store
* @param msgpath path to a maildir
* @param stamp a timestamp
*/
void mu_store_xapian_set_timestamp (MuStoreXapian *store,
void mu_store_set_timestamp (MuStore *store,
const char* msgpath,
time_t stamp);
/**
/**
* get the timestamp for a directory
*
* @param store a valid store
@ -133,10 +133,10 @@ void mu_store_xapian_set_timestamp (MuStoreXapian *store,
*
* @return the timestamp, or 0 in case of error
*/
time_t mu_store_xapian_get_timestamp (MuStoreXapian *store,
time_t mu_store_get_timestamp (MuStore *store,
const char* msgpath);
/**
/**
* call a function for each document in the database
*
* @param self a valid store
@ -146,12 +146,12 @@ time_t mu_store_xapian_get_timestamp (MuStoreXapian *store,
* @return MU_OK if all went well, MU_STOP if the foreach was interrupted,
* MU_ERROR in case of error
*/
typedef MuResult (*MuStoreXapianForeachFunc) (const char* path,
typedef MuResult (*MuStoreForeachFunc) (const char* path,
void *user_data);
MuResult mu_store_xapian_foreach (MuStoreXapian *self,
MuStoreXapianForeachFunc func,
void *user_data);
MuResult mu_store_foreach (MuStore *self,
MuStoreForeachFunc func,
void *user_data);
G_END_DECLS
#endif /*__MU_STORE_XAPIAN_H__*/
#endif /*__MU_STORE_H__*/