* minor changes, trailing whitespace fixes

This commit is contained in:
Dirk-Jan C. Binnema
2011-08-29 23:38:55 +03:00
parent 93ec32dcbf
commit fbc786f2fc
10 changed files with 528 additions and 506 deletions

View File

@ -348,13 +348,13 @@ get_query (MuConfig *opts)
static gboolean static gboolean
db_is_ready (const char *xpath) db_is_ready (const char *xpath)
{ {
if (mu_util_xapian_is_empty (xpath)) { if (mu_store_database_is_empty (xpath)) {
g_warning ("database is empty; use 'mu index' to " g_warning ("database is empty; use 'mu index' to "
"add messages"); "add messages");
return FALSE; return FALSE;
} }
if (mu_util_xapian_needs_upgrade (xpath)) { if (mu_store_database_needs_upgrade (xpath)) {
upgrade_warning (); upgrade_warning ();
return FALSE; return FALSE;
} }

View File

@ -34,6 +34,7 @@
#include "mu-util.h" #include "mu-util.h"
#include "mu-msg.h" #include "mu-msg.h"
#include "mu-index.h" #include "mu-index.h"
#include "mu-store.h"
#include "mu-runtime.h" #include "mu-runtime.h"
static gboolean MU_CAUGHT_SIGNAL; static gboolean MU_CAUGHT_SIGNAL;
@ -201,7 +202,7 @@ database_version_check_and_update (MuConfig *opts)
xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB); xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB);
ccache = mu_runtime_path (MU_RUNTIME_PATH_CONTACTS); ccache = mu_runtime_path (MU_RUNTIME_PATH_CONTACTS);
if (mu_util_xapian_is_empty (xpath)) if (mu_store_database_is_empty (xpath))
return TRUE; return TRUE;
/* when rebuilding, we empty the database before doing /* when rebuilding, we empty the database before doing
@ -210,17 +211,17 @@ database_version_check_and_update (MuConfig *opts)
opts->reindex = TRUE; opts->reindex = TRUE;
g_message ("clearing database [%s]", xpath); g_message ("clearing database [%s]", xpath);
g_message ("clearing contacts-cache [%s]", ccache); g_message ("clearing contacts-cache [%s]", ccache);
return mu_util_xapian_clear (xpath, ccache); return mu_store_database_clear (xpath, ccache);
} }
if (!mu_util_xapian_needs_upgrade (xpath)) if (!mu_store_database_needs_upgrade (xpath))
return TRUE; /* ok, nothing to do */ return TRUE; /* ok, nothing to do */
/* ok, database is not up to date */ /* ok, database is not up to date */
if (opts->autoupgrade) { if (opts->autoupgrade) {
opts->reindex = TRUE; opts->reindex = TRUE;
g_message ("auto-upgrade: clearing old database and cache"); g_message ("auto-upgrade: clearing old database and cache");
return mu_util_xapian_clear (xpath, ccache); return mu_store_database_clear (xpath, ccache);
} }
update_warning (); update_warning ();

View File

@ -46,7 +46,12 @@
static gboolean static gboolean
view_msg_sexp (MuMsg *msg) view_msg_sexp (MuMsg *msg)
{ {
fputs (mu_msg_to_sexp (msg, NULL, FALSE), stdout); char *sexp;
sexp = mu_msg_to_sexp (msg, NULL, FALSE);
fputs (sexp, stdout);
g_free (sexp);
return TRUE; return TRUE;
} }
@ -173,8 +178,10 @@ handle_msg (const char *fname, MuConfig *opts, MuError *code)
msg = mu_msg_new_from_file (fname, NULL, &err); msg = mu_msg_new_from_file (fname, NULL, &err);
if (!msg) { if (!msg) {
g_warning ("error: %s", err->message); if (err && err->message) {
g_error_free (err); g_warning ("%s", err->message);
g_error_free (err);
}
*code = MU_ERROR; *code = MU_ERROR;
return FALSE; return FALSE;
} }
@ -395,9 +402,10 @@ get_store (void)
GError *err; GError *err;
err = NULL; err = NULL;
store = mu_store_new (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), store = mu_store_new_writable
mu_runtime_path(MU_RUNTIME_PATH_CONTACTS), (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
&err); mu_runtime_path(MU_RUNTIME_PATH_CONTACTS),
&err);
if (!store) { if (!store) {
if (err) { if (err) {
g_warning ("store error: %s", err->message); g_warning ("store error: %s", err->message);
@ -407,11 +415,9 @@ get_store (void)
} }
return store; return store;
} }
MuError MuError
mu_cmd_add (MuConfig *opts) mu_cmd_add (MuConfig *opts)
{ {
@ -496,3 +502,6 @@ mu_cmd_remove (MuConfig *opts)
return allok ? MU_OK : MU_ERROR; return allok ? MU_OK : MU_ERROR;
} }

View File

@ -33,8 +33,8 @@ G_BEGIN_DECLS
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeded, * @return MU_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_mkdir (MuConfig *opts); MuError mu_cmd_mkdir (MuConfig *opts);
@ -44,8 +44,8 @@ MuError mu_cmd_mkdir (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeded, * @return MU_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_view (MuConfig *opts); MuError mu_cmd_view (MuConfig *opts);
@ -53,10 +53,11 @@ MuError mu_cmd_view (MuConfig *opts);
/** /**
* execute the 'index' command * execute the 'index' command
* *
* @param store store object to use
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeded, * @return MU_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_index (MuConfig *opts); MuError mu_cmd_index (MuConfig *opts);
@ -64,10 +65,11 @@ MuError mu_cmd_index (MuConfig *opts);
/** /**
* execute the 'cleanup' command * execute the 'cleanup' command
* *
* @param store store object to use
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_cleanup (MuConfig *opts); MuError mu_cmd_cleanup (MuConfig *opts);
@ -76,9 +78,9 @@ MuError mu_cmd_cleanup (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds and * @return MU_OK (0) if the command succeeds and
* >MU_EXITCODE_OK (0) results, MU_EXITCODE_NO_MATCHES if the command * >MU_OK (0) results, MU_EXITCODE_NO_MATCHES if the command
* succeeds but there no matches, MU_EXITCODE_ERROR for all other errors * succeeds but there no matches, some error code for all other errors
*/ */
MuError mu_cmd_find (MuConfig *opts); MuError mu_cmd_find (MuConfig *opts);
@ -88,8 +90,8 @@ MuError mu_cmd_find (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_extract (MuConfig *opts); MuError mu_cmd_extract (MuConfig *opts);
@ -99,21 +101,18 @@ MuError mu_cmd_extract (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_mv (MuConfig *opts); MuError mu_cmd_mv (MuConfig *opts);
/** /**
* execute the cfind command * execute the cfind command
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_cfind (MuConfig *opts); MuError mu_cmd_cfind (MuConfig *opts);
@ -123,8 +122,8 @@ MuError mu_cmd_cfind (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_add (MuConfig *opts); MuError mu_cmd_add (MuConfig *opts);
@ -133,11 +132,23 @@ MuError mu_cmd_add (MuConfig *opts);
* *
* @param opts configuration options * @param opts configuration options
* *
* @return MU_EXITCODE_OK (0) if the command succeeds, * @return MU_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise * some error code otherwise
*/ */
MuError mu_cmd_remove (MuConfig *opts); MuError mu_cmd_remove (MuConfig *opts);
/**
* execute the server command
*
* @param opts configuration options
*
* @return MU_OK (0) if the command succeeds,
* some error code otherwise
*/
MuError mu_cmd_server (MuConfig *opts);
G_END_DECLS G_END_DECLS
#endif /*__MU_CMD_H__*/ #endif /*__MU_CMD_H__*/

View File

@ -55,7 +55,7 @@ mu_index_new (const char *xpath, const char* contacts_cache, GError **err)
index = g_new0 (MuIndex, 1); index = g_new0 (MuIndex, 1);
index->_store = mu_store_new (xpath, contacts_cache, err); index->_store = mu_store_new_writable (xpath, contacts_cache, err);
if (!index->_store) { if (!index->_store) {
g_warning ("%s: failed to open xapian store (%s)", g_warning ("%s: failed to open xapian store (%s)",
__FUNCTION__, xpath); __FUNCTION__, xpath);
@ -70,11 +70,11 @@ mu_index_new (const char *xpath, const char* contacts_cache, GError **err)
* race-condition here, between mu_index_new and * race-condition here, between mu_index_new and
* mu_index_run. Maybe do the check in mu_index_run * mu_index_run. Maybe do the check in mu_index_run
* instead? */ * instead? */
if (mu_util_xapian_is_empty (xpath)) if (mu_store_database_is_empty (xpath))
index->_needs_reindex = FALSE; index->_needs_reindex = FALSE;
else else
index->_needs_reindex = index->_needs_reindex =
mu_util_xapian_needs_upgrade (xpath); mu_store_database_needs_upgrade (xpath);
return index; return index;
} }
@ -171,7 +171,7 @@ run_msg_callback_maybe (MuIndexCallbackData *data)
return MU_OK; return MU_OK;
result = data->_idx_msg_cb (data->_stats, data->_user_data); result = data->_idx_msg_cb (data->_stats, data->_user_data);
if G_UNLIKELY((result != MU_OK && result != MU_STOP)) if (G_UNLIKELY(result != MU_OK && result != MU_STOP))
g_warning ("error in callback"); g_warning ("error in callback");
return result; return result;
@ -409,7 +409,6 @@ mu_index_stats (MuIndex *index, const char* path,
NULL,&cb_data); NULL,&cb_data);
} }
struct _CleanupData { struct _CleanupData {
MuStore *_store; MuStore *_store;
MuIndexStats *_stats; MuIndexStats *_stats;

View File

@ -297,7 +297,7 @@ mu_msg_to_sexp (MuMsg *msg, const MuMsgIterThreadInfo *ti, gboolean dbonly)
if (!dbonly) if (!dbonly)
append_sexp_message_file_attr (gstr, msg); append_sexp_message_file_attr (gstr, msg);
g_string_append (gstr, ")\n;;eom\n"); g_string_append (gstr, ")\n;;eox\n");
return g_string_free (gstr, FALSE); return g_string_free (gstr, FALSE);
} }

View File

@ -72,11 +72,6 @@ msg_new (void)
{ {
MuMsg *self; MuMsg *self;
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
self = g_slice_new0 (MuMsg); self = g_slice_new0 (MuMsg);
self->_refcount = 1; self->_refcount = 1;
@ -93,6 +88,11 @@ mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
g_return_val_if_fail (path, NULL); g_return_val_if_fail (path, NULL);
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
msgfile = mu_msg_file_new (path, mdir, err); msgfile = mu_msg_file_new (path, mdir, err);
if (!msgfile) if (!msgfile)
return NULL; return NULL;
@ -112,6 +112,11 @@ mu_msg_new_from_doc (XapianDocument *doc, GError **err)
g_return_val_if_fail (doc, NULL); g_return_val_if_fail (doc, NULL);
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
msgdoc = mu_msg_doc_new (doc, err); msgdoc = mu_msg_doc_new (doc, err);
if (!msgdoc) if (!msgdoc)
return NULL; return NULL;

View File

@ -157,9 +157,17 @@ private:
static void add_prefix (MuMsgFieldId field, Xapian::QueryParser* qparser); static void add_prefix (MuMsgFieldId field, Xapian::QueryParser* qparser);
struct _MuQuery { struct _MuQuery {
_MuQuery (const char* dbpath): _MuQuery (const char* dbpath) {
_db (Xapian::Database(dbpath)) { init ((Xapian::Database(dbpath)));
}
_MuQuery (Xapian::Database* db) {
init (*db);
}
void init (Xapian::Database db) {
_db = db;
_qparser.set_database (_db); _qparser.set_database (_db);
_qparser.set_default_op (Xapian::Query::OP_AND); _qparser.set_default_op (Xapian::Query::OP_AND);
@ -247,14 +255,14 @@ mu_query_new (const char* xpath, GError **err)
return NULL; return NULL;
} }
if (mu_util_xapian_needs_upgrade (xpath)) { if (mu_store_database_needs_upgrade (xpath)) {
g_set_error (err, 0, MU_ERROR_XAPIAN_NOT_UP_TO_DATE, g_set_error (err, 0, MU_ERROR_XAPIAN_NOT_UP_TO_DATE,
"%s is not up-to-date, needs a full update", "%s is not up-to-date, needs a full update",
xpath); xpath);
return NULL; return NULL;
} }
if (mu_util_xapian_is_empty (xpath)) if (mu_store_database_is_empty (xpath))
g_warning ("database %s is empty; nothing to do", xpath); g_warning ("database %s is empty; nothing to do", xpath);
try { try {
@ -267,6 +275,31 @@ mu_query_new (const char* xpath, GError **err)
} }
MuQuery*
mu_query_new_from_store (MuStore *store, GError **err)
{
g_return_val_if_fail (store, NULL);
try {
XapianDatabase *db;
db = mu_store_get_read_only_database(store);
return new MuQuery (reinterpret_cast<Xapian::Database*>(db));
} MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN (err, MU_ERROR_XAPIAN, NULL);
return 0;
}
MuQuery *mu_query_new_from_store (MuStore *store, GError **err)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
void void
mu_query_destroy (MuQuery *self) mu_query_destroy (MuQuery *self)
{ {

View File

@ -21,8 +21,9 @@
#define __MU_QUERY_H__ #define __MU_QUERY_H__
#include <glib.h> #include <glib.h>
#include <mu-store.h>
#include <mu-msg-iter.h> #include <mu-msg-iter.h>
#include <mu-util.h> /* for MuResult, MuError */ #include <mu-util.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -45,6 +46,25 @@ typedef struct _MuQuery MuQuery;
MuQuery *mu_query_new (const char* path, GError **err) MuQuery *mu_query_new (const char* path, GError **err)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
/**
* create a new MuQuery instance using an existing MuStore
*
* @param store a valid MuStore object
* @param err receives error information (if there is any); if
* function returns non-NULL, err will _not_be set. err can be NULL
* possble errors (err->code) are MU_ERROR_XAPIAN_DIR and
* MU_ERROR_XAPIAN_NOT_UPTODATE
*
* @return a new MuQuery instance, or NULL in case of error.
* when the instance is no longer needed, use mu_query_destroy
* to free it
*/
MuQuery *mu_query_new_from_store (MuStore *store, GError **err)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
/** /**
* destroy the MuQuery instance * destroy the MuQuery instance
* *

View File

@ -192,65 +192,6 @@ gboolean mu_util_play (const char *path,
gboolean allow_local, gboolean allow_remote); gboolean allow_local, gboolean allow_remote);
/**
" * get the version of the xapian database (ie., the version of the
* 'schema' we are using). If this version != MU_XAPIAN_DB_VERSION,
* it's means we need to a full reindex.
*
* @param xpath path to the xapian database
*
* @return the version of the database as a newly allocated string
* (free with g_free); if there is no version yet, it will return NULL
*/
gchar* mu_util_xapian_dbversion (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT;
/**
* check whether the database needs to be upgraded, e.g., when it was
* created with a different version of mu
*
* @param xpath path to the database dir
*
* @return TRUE if the database needs upgrading, FALSE otherwise
*/
gboolean mu_util_xapian_needs_upgrade (const gchar *xpath);
/**
* check whether the database is empty (contains 0 documents); in
* addition, a non-existing database is considered 'empty' too
*
* @param xpath path to the xapian database
*
* @return TRUE if the database is empty, FALSE otherwise
*/
gboolean mu_util_xapian_is_empty (const gchar *xpath);
/**
* clear the database, ie., remove all of the contents. This is a
* destructive operation, but the database can be restored be doing a
* full scan of the maildirs. Also, clear the contacts cache file
*
* @param xpath path to the database
* @param ccache path to the contacts cache file
*
* @return TRUE if the clearing succeeded, FALSE otherwise.
*/
gboolean mu_util_xapian_clear (const gchar *xpath,
const gchar *ccache);
/**
* check if the database is locked for writing
*
* @param xpath path to a xapian database
*
* @return TRUE if it is locked, FALSE otherwise (or in case of error)
*/
gboolean mu_util_xapian_is_locked (const gchar *xpath);
/** /**
* convert a string array in to a string, with the elements separated * convert a string array in to a string, with the elements separated
* by ' ' * by ' '
@ -313,6 +254,9 @@ typedef gpointer XapianDocument;
*/ */
typedef gpointer XapianEnquire; typedef gpointer XapianEnquire;
/** /**
* *
* don't repeat these catch blocks everywhere... * don't repeat these catch blocks everywhere...