Skip to content

Commit

Permalink
* mu-index: take a MuStore rather than paths as arg
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Aug 30, 2011
1 parent 1c4016b commit c1d0ccc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 59 deletions.
30 changes: 11 additions & 19 deletions src/mu-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,27 @@ struct _MuIndex {
};

MuIndex*
mu_index_new (const char *xpath, const char* contacts_cache, GError **err)
mu_index_new (MuStore *store, GError **err)
{
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->_store = mu_store_new_writable (xpath, contacts_cache, err);
if (!index->_store) {
g_warning ("%s: failed to open xapian store (%s)",
__FUNCTION__, xpath);
g_free (index);
return NULL;
}
index->_store = mu_store_ref (store);

/* set the default max file size */
index->_max_filesize = MU_INDEX_MAX_FILE_SIZE;

/* see we need to reindex the database; note, there is a small
* 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))
if (mu_store_count (store) == 0)
index->_needs_reindex = FALSE;
else
index->_needs_reindex =
mu_store_database_needs_upgrade (xpath);

/* FIXME */
/* else */
/* index->_needs_reindex = */
/* mu_store_database_needs_upgrade (xpath); */

return index;
}
Expand All @@ -86,8 +79,7 @@ mu_index_destroy (MuIndex *index)
return;

g_free (index->_last_used_maildir);
mu_store_destroy (index->_store);

mu_store_unref (index->_store);
g_free (index);
}

Expand Down
78 changes: 38 additions & 40 deletions src/mu-index.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
**
** You should have received a copy of the GNU General Public License
** 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__
Expand All @@ -25,6 +25,7 @@
#include <stdlib.h>
#include <glib.h>
#include <mu-util.h> /* for MuResult */
#include <mu-store.h>

G_BEGIN_DECLS

Expand All @@ -46,22 +47,19 @@ typedef struct _MuIndexStats MuIndexStats;
* doing anything with the returned Index object, make sure you haved
* called g_type_init, and mu_msg_init somewhere in your code.
*
* @param xpath path to the 'homedir'; the xapian directory will be
* this homedir/xapian
* @param contacts_cache file to store the cache of contacts, or NULL
* @param store a writable MuStore object
* @param err to receive error or NULL; there are only errors when this
* function returns NULL. Possible errors: see mu-error.h
*
*
* @return a new MuIndex instance, or NULL in case of error
*/
MuIndex* mu_index_new (const char* muhome, const char* contacts_cache,
GError **err)
MuIndex* mu_index_new (MuStore *store, GError **err)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;


/**
* destroy the index instance
*
*
* @param index a MuIndex instance, or NULL
*/
void mu_index_destroy (MuIndex *index);
Expand All @@ -72,7 +70,7 @@ void mu_index_destroy (MuIndex *index);
* default (MU_INDEX_MAX_FILE_SIZE). Note that the maximum size is a
* protection against mu (or the libraries it uses) allocating too
* much memory, which can lead to problems
*
*
* @param index a mu index object
* @param max_size the maximum msg size, or 0 to reset to the default
*/
Expand All @@ -82,7 +80,7 @@ void mu_index_set_max_msg_size (MuIndex *index, guint max_size);
/**
* change batch size for Xapian store transaction (see
* 'mu_store_set_batch_size')
*
*
* @param index a mu index object
* @param max_size the batch size, or 0 to reset to the default
*/
Expand All @@ -92,42 +90,42 @@ void mu_index_set_xbatch_size (MuIndex *index, guint xbatchsize);
/**
* get the maildir for the last run of indexing for the
* current database
*
*
* @param index MuIndex object
*
*
* @return the last used maildir, or NULL
*/
const char* mu_index_last_used_maildir (MuIndex *index);


/**
* 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
*
* @return MU_OK to continue, MU_STOP to stop, or MU_ERROR in
* 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
*
*
* @param path dirpath we just entered / left
* @param enter did we enter (TRUE) or leave(FALSE) the dir?
* @param user_data pointer to user data
*
* @return MU_OK to contiue, MU_STOP to stopd or MU_ERROR in
* case of some error.
*/
typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
void *user_data);

/**
* start the indexing process
*
* start the indexing process
*
* @param index a valid MuIndex instance
* @param path the path to index. This must be an absolute path
* @param force if != 0, force re-indexing already index messages; this is
Expand All @@ -137,34 +135,34 @@ typedef MuError (*MuIndexDirCallback) (const char* path, gboolean enter,
* for cumulative stats from multiple calls. If needed, you can use
* @mu_index_stats_clear before calling this function
* @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
*
* @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
* 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,
MuIndexDirCallback dir_cb, void *user_data);

/**
* 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
* 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
*
*
* @param index a valid MuIndex instance
* @param path the path to get stats for; this must be an absolute path
* @param stats a structure with some statistics about the results;
* note that this function does *not* reset the struct values to allow
* for cumulative stats from multiple calls. If needed, you can use
* @mu_index_stats_clear before calling this function
* @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
* 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
* case of some error.
*/
Expand All @@ -176,27 +174,27 @@ MuError mu_index_stats (MuIndex *index, const char* path, MuIndexStats *stats,

/**
* callback function called for each message
*
* @param MuIndexCleanupCallback
*
*
* @param MuIndexCleanupCallback
*
* @return a MuResult
*/
typedef MuError (*MuIndexCleanupDeleteCallback) (MuIndexStats *stats,
void *user_data);
void *user_data);

/**
* cleanup the database; ie. remove entries for which no longer a corresponding
* file exists in the maildir
*
*
* @param index a valid MuIndex instance
* @param stats a structure with some statistics about the results;
* note that this function does *not* reset the struct values to allow
* for cumulative stats from multiple calls. If needed, you can use
* @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
*
* @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
* case of some error.
*/
Expand All @@ -206,9 +204,9 @@ MuError mu_index_cleanup (MuIndex *index, MuIndexStats *stats,

/**
* clear the stats structure
*
*
* @param stats a MuIndexStats object
*
*
* @return TRUE if stats != NULL, FALSE otherwise
*/
gboolean mu_index_stats_clear (MuIndexStats *stats);
Expand Down

0 comments on commit c1d0ccc

Please sign in to comment.