* mu-index: take a MuStore rather than paths as arg
This commit is contained in:
@ -47,34 +47,27 @@ struct _MuIndex {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MuIndex*
|
MuIndex*
|
||||||
mu_index_new (const char *xpath, const char* contacts_cache, GError **err)
|
mu_index_new (MuStore *store, GError **err)
|
||||||
{
|
{
|
||||||
MuIndex *index;
|
MuIndex *index;
|
||||||
|
|
||||||
g_return_val_if_fail (xpath, NULL);
|
g_return_val_if_fail (store, NULL);
|
||||||
|
g_return_val_if_fail (!mu_store_is_read_only(store), NULL);
|
||||||
|
|
||||||
index = g_new0 (MuIndex, 1);
|
index = g_new0 (MuIndex, 1);
|
||||||
|
|
||||||
index->_store = mu_store_new_writable (xpath, contacts_cache, err);
|
index->_store = mu_store_ref (store);
|
||||||
if (!index->_store) {
|
|
||||||
g_warning ("%s: failed to open xapian store (%s)",
|
|
||||||
__FUNCTION__, xpath);
|
|
||||||
g_free (index);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the default max file size */
|
/* set the default max file size */
|
||||||
index->_max_filesize = MU_INDEX_MAX_FILE_SIZE;
|
index->_max_filesize = MU_INDEX_MAX_FILE_SIZE;
|
||||||
|
|
||||||
/* see we need to reindex the database; note, there is a small
|
if (mu_store_count (store) == 0)
|
||||||
* race-condition here, between mu_index_new and
|
|
||||||
* mu_index_run. Maybe do the check in mu_index_run
|
|
||||||
* instead? */
|
|
||||||
if (mu_store_database_is_empty (xpath))
|
|
||||||
index->_needs_reindex = FALSE;
|
index->_needs_reindex = FALSE;
|
||||||
else
|
|
||||||
index->_needs_reindex =
|
/* FIXME */
|
||||||
mu_store_database_needs_upgrade (xpath);
|
/* else */
|
||||||
|
/* index->_needs_reindex = */
|
||||||
|
/* mu_store_database_needs_upgrade (xpath); */
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@ -86,8 +79,7 @@ mu_index_destroy (MuIndex *index)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
g_free (index->_last_used_maildir);
|
g_free (index->_last_used_maildir);
|
||||||
mu_store_destroy (index->_store);
|
mu_store_unref (index->_store);
|
||||||
|
|
||||||
g_free (index);
|
g_free (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,16 +7,16 @@
|
|||||||
** it under the terms of the GNU General Public License as published by
|
** it under the terms of the GNU General Public License as published by
|
||||||
** the Free Software Foundation; either version 3 of the License, or
|
** the Free Software Foundation; either version 3 of the License, or
|
||||||
** (at your option) any later version.
|
** (at your option) any later version.
|
||||||
**
|
**
|
||||||
** This program is distributed in the hope that it will be useful,
|
** This program is distributed in the hope that it will be useful,
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
** GNU General Public License for more details.
|
** GNU General Public License for more details.
|
||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with this program; if not, write to the Free Software Foundation,
|
** along with this program; if not, write to the Free Software Foundation,
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MU_INDEX_H__
|
#ifndef __MU_INDEX_H__
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <mu-util.h> /* for MuResult */
|
#include <mu-util.h> /* for MuResult */
|
||||||
|
#include <mu-store.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -46,22 +47,19 @@ typedef struct _MuIndexStats MuIndexStats;
|
|||||||
* doing anything with the returned Index object, make sure you haved
|
* doing anything with the returned Index object, make sure you haved
|
||||||
* called g_type_init, and mu_msg_init somewhere in your code.
|
* called g_type_init, and mu_msg_init somewhere in your code.
|
||||||
*
|
*
|
||||||
* @param xpath path to the 'homedir'; the xapian directory will be
|
* @param store a writable MuStore object
|
||||||
* this homedir/xapian
|
|
||||||
* @param contacts_cache file to store the cache of contacts, or NULL
|
|
||||||
* @param err to receive error or NULL; there are only errors when this
|
* @param err to receive error or NULL; there are only errors when this
|
||||||
* function returns NULL. Possible errors: see mu-error.h
|
* function returns NULL. Possible errors: see mu-error.h
|
||||||
*
|
*
|
||||||
* @return a new MuIndex instance, or NULL in case of error
|
* @return a new MuIndex instance, or NULL in case of error
|
||||||
*/
|
*/
|
||||||
MuIndex* mu_index_new (const char* muhome, const char* contacts_cache,
|
MuIndex* mu_index_new (MuStore *store, GError **err)
|
||||||
GError **err)
|
|
||||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroy the index instance
|
* destroy the index instance
|
||||||
*
|
*
|
||||||
* @param index a MuIndex instance, or NULL
|
* @param index a MuIndex instance, or NULL
|
||||||
*/
|
*/
|
||||||
void mu_index_destroy (MuIndex *index);
|
void mu_index_destroy (MuIndex *index);
|
||||||
@ -72,7 +70,7 @@ void mu_index_destroy (MuIndex *index);
|
|||||||
* default (MU_INDEX_MAX_FILE_SIZE). Note that the maximum size is a
|
* default (MU_INDEX_MAX_FILE_SIZE). Note that the maximum size is a
|
||||||
* protection against mu (or the libraries it uses) allocating too
|
* protection against mu (or the libraries it uses) allocating too
|
||||||
* much memory, which can lead to problems
|
* much memory, which can lead to problems
|
||||||
*
|
*
|
||||||
* @param index a mu index object
|
* @param index a mu index object
|
||||||
* @param max_size the maximum msg size, or 0 to reset to the default
|
* @param max_size the maximum msg size, or 0 to reset to the default
|
||||||
*/
|
*/
|
||||||
@ -82,7 +80,7 @@ void mu_index_set_max_msg_size (MuIndex *index, guint max_size);
|
|||||||
/**
|
/**
|
||||||
* change batch size for Xapian store transaction (see
|
* change batch size for Xapian store transaction (see
|
||||||
* 'mu_store_set_batch_size')
|
* 'mu_store_set_batch_size')
|
||||||
*
|
*
|
||||||
* @param index a mu index object
|
* @param index a mu index object
|
||||||
* @param max_size the batch size, or 0 to reset to the default
|
* @param max_size the batch size, or 0 to reset to the default
|
||||||
*/
|
*/
|
||||||
@ -92,9 +90,9 @@ void mu_index_set_xbatch_size (MuIndex *index, guint xbatchsize);
|
|||||||
/**
|
/**
|
||||||
* get the maildir for the last run of indexing for the
|
* get the maildir for the last run of indexing for the
|
||||||
* current database
|
* current database
|
||||||
*
|
*
|
||||||
* @param index MuIndex object
|
* @param index MuIndex object
|
||||||
*
|
*
|
||||||
* @return the last used maildir, or NULL
|
* @return the last used maildir, or NULL
|
||||||
*/
|
*/
|
||||||
const char* mu_index_last_used_maildir (MuIndex *index);
|
const char* mu_index_last_used_maildir (MuIndex *index);
|
||||||
@ -102,19 +100,19 @@ const char* mu_index_last_used_maildir (MuIndex *index);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* callback function for mu_index_(run|stats|cleanup), for each message
|
* callback function for mu_index_(run|stats|cleanup), for each message
|
||||||
*
|
*
|
||||||
* @param stats pointer to structure to receive statistics data
|
* @param stats pointer to structure to receive statistics data
|
||||||
* @param user_data pointer to user data
|
* @param user_data pointer to user data
|
||||||
*
|
*
|
||||||
* @return MU_OK to continue, MU_STOP to stop, or MU_ERROR in
|
* @return MU_OK to continue, MU_STOP to stop, or MU_ERROR in
|
||||||
* case of some error.
|
* case of some error.
|
||||||
*/
|
*/
|
||||||
typedef MuError (*MuIndexMsgCallback) (MuIndexStats* stats, void *user_data);
|
typedef MuError (*MuIndexMsgCallback) (MuIndexStats* stats, void *user_data);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* callback function for mu_index_(run|stats|cleanup), for each dir enter/leave
|
* callback function for mu_index_(run|stats|cleanup), for each dir enter/leave
|
||||||
*
|
*
|
||||||
* @param path dirpath we just entered / left
|
* @param path dirpath we just entered / left
|
||||||
* @param enter did we enter (TRUE) or leave(FALSE) the dir?
|
* @param enter did we enter (TRUE) or leave(FALSE) the dir?
|
||||||
* @param user_data pointer to user data
|
* @param user_data pointer to user data
|
||||||
@ -122,12 +120,12 @@ typedef MuError (*MuIndexMsgCallback) (MuIndexStats* stats, void *user_data);
|
|||||||
* @return MU_OK to contiue, MU_STOP to stopd or MU_ERROR in
|
* @return MU_OK to contiue, MU_STOP to stopd or MU_ERROR in
|
||||||
* case of some error.
|
* case of some error.
|
||||||
*/
|
*/
|
||||||
typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
|
typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the indexing process
|
* start the indexing process
|
||||||
*
|
*
|
||||||
* @param index a valid MuIndex instance
|
* @param index a valid MuIndex instance
|
||||||
* @param path the path to index. This must be an absolute path
|
* @param path the path to index. This must be an absolute path
|
||||||
* @param force if != 0, force re-indexing already index messages; this is
|
* @param force if != 0, force re-indexing already index messages; this is
|
||||||
@ -137,23 +135,23 @@ typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
|
|||||||
* for cumulative stats from multiple calls. If needed, you can use
|
* for cumulative stats from multiple calls. If needed, you can use
|
||||||
* @mu_index_stats_clear before calling this function
|
* @mu_index_stats_clear before calling this function
|
||||||
* @param cb_msg a callback function called for every msg indexed;
|
* @param cb_msg a callback function called for every msg indexed;
|
||||||
* @param cb_dir a callback function called for every dir entered/left or NULL
|
* @param cb_dir a callback function called for every dir entered/left or NULL
|
||||||
* @param user_data a user pointer that will be passed to the callback function
|
* @param user_data a user pointer that will be passed to the callback function
|
||||||
*
|
*
|
||||||
* @return MU_OK if the stats gathering was completed succesfully,
|
* @return MU_OK if the stats gathering was completed succesfully,
|
||||||
* MU_STOP if the user stopped or MU_ERROR in
|
* MU_STOP if the user stopped or MU_ERROR in
|
||||||
* case of some error.
|
* case of some error.
|
||||||
*/
|
*/
|
||||||
MuError mu_index_run (MuIndex *index, const char* path, gboolean force,
|
MuError mu_index_run (MuIndex *index, const char* path, gboolean force,
|
||||||
MuIndexStats *stats, MuIndexMsgCallback msg_cb,
|
MuIndexStats *stats, MuIndexMsgCallback msg_cb,
|
||||||
MuIndexDirCallback dir_cb, void *user_data);
|
MuIndexDirCallback dir_cb, void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gather some statistics about the Maildir; this is usually much faster
|
* gather some statistics about the Maildir; this is usually much faster
|
||||||
* than mu_index_run, and can thus be used to provide some information to the user
|
* than mu_index_run, and can thus be used to provide some information to the user
|
||||||
* note though that the statistics may be different from the reality that
|
* note though that the statistics may be different from the reality that
|
||||||
* mu_index_run sees, when there are updates in the Maildir
|
* mu_index_run sees, when there are updates in the Maildir
|
||||||
*
|
*
|
||||||
* @param index a valid MuIndex instance
|
* @param index a valid MuIndex instance
|
||||||
* @param path the path to get stats for; this must be an absolute path
|
* @param path the path to get stats for; this must be an absolute path
|
||||||
* @param stats a structure with some statistics about the results;
|
* @param stats a structure with some statistics about the results;
|
||||||
@ -161,10 +159,10 @@ MuError mu_index_run (MuIndex *index, const char* path, gboolean force,
|
|||||||
* for cumulative stats from multiple calls. If needed, you can use
|
* for cumulative stats from multiple calls. If needed, you can use
|
||||||
* @mu_index_stats_clear before calling this function
|
* @mu_index_stats_clear before calling this function
|
||||||
* @param msg_cb a callback function which will be called for every msg;
|
* @param msg_cb a callback function which will be called for every msg;
|
||||||
* @param dir_cb a callback function which will be called for every dir or NULL
|
* @param dir_cb a callback function which will be called for every dir or NULL
|
||||||
* @param user_data a user pointer that will be passed to the callback function
|
* @param user_data a user pointer that will be passed to the callback function
|
||||||
* xb
|
* xb
|
||||||
* @return MU_OK if the stats gathering was completed succesfully,
|
* @return MU_OK if the stats gathering was completed succesfully,
|
||||||
* MU_STOP if the user stopped or MU_ERROR in
|
* MU_STOP if the user stopped or MU_ERROR in
|
||||||
* case of some error.
|
* case of some error.
|
||||||
*/
|
*/
|
||||||
@ -176,27 +174,27 @@ MuError mu_index_stats (MuIndex *index, const char* path, MuIndexStats *stats,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* callback function called for each message
|
* callback function called for each message
|
||||||
*
|
*
|
||||||
* @param MuIndexCleanupCallback
|
* @param MuIndexCleanupCallback
|
||||||
*
|
*
|
||||||
* @return a MuResult
|
* @return a MuResult
|
||||||
*/
|
*/
|
||||||
typedef MuError (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
|
typedef MuError (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cleanup the database; ie. remove entries for which no longer a corresponding
|
* cleanup the database; ie. remove entries for which no longer a corresponding
|
||||||
* file exists in the maildir
|
* file exists in the maildir
|
||||||
*
|
*
|
||||||
* @param index a valid MuIndex instance
|
* @param index a valid MuIndex instance
|
||||||
* @param stats a structure with some statistics about the results;
|
* @param stats a structure with some statistics about the results;
|
||||||
* note that this function does *not* reset the struct values to allow
|
* note that this function does *not* reset the struct values to allow
|
||||||
* for cumulative stats from multiple calls. If needed, you can use
|
* for cumulative stats from multiple calls. If needed, you can use
|
||||||
* @mu_index_stats_clear before calling this function
|
* @mu_index_stats_clear before calling this function
|
||||||
* @param cb a callback function which will be called for every msg;
|
* @param cb a callback function which will be called for every msg;
|
||||||
* @param user_data a user pointer that will be passed to the callback function
|
* @param user_data a user pointer that will be passed to the callback function
|
||||||
*
|
*
|
||||||
* @return MU_OK if the stats gathering was completed succesfully,
|
* @return MU_OK if the stats gathering was completed succesfully,
|
||||||
* MU_STOP if the user stopped or MU_ERROR in
|
* MU_STOP if the user stopped or MU_ERROR in
|
||||||
* case of some error.
|
* case of some error.
|
||||||
*/
|
*/
|
||||||
@ -206,9 +204,9 @@ MuError mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* clear the stats structure
|
* clear the stats structure
|
||||||
*
|
*
|
||||||
* @param stats a MuIndexStats object
|
* @param stats a MuIndexStats object
|
||||||
*
|
*
|
||||||
* @return TRUE if stats != NULL, FALSE otherwise
|
* @return TRUE if stats != NULL, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_index_stats_clear (MuIndexStats *stats);
|
gboolean mu_index_stats_clear (MuIndexStats *stats);
|
||||||
|
|||||||
Reference in New Issue
Block a user