From 022d08530ec4b7b49dad964bf7c8242141edb832 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 3 Jan 2010 23:54:22 +0200 Subject: [PATCH] * mu_index: WIP: mu_index_cleanup --- src/mu-index.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- src/mu-index.h | 2 -- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/mu-index.c b/src/mu-index.c index cc09bc81..024d5452 100644 --- a/src/mu-index.c +++ b/src/mu-index.c @@ -282,10 +282,50 @@ mu_index_stats (MuIndex *index, const char* path, } -MuResult mu_index_cleanup (MuIndex *index, MuIndexStats *result, - MuIndexCleanupDeleteCallback cb, - void *user_data) -{ - return MU_OK; +struct _CleanupData { + MuStoreXapian *_xapian; + MuIndexStats *_stats; + MuIndexCleanupDeleteCallback _cb; + void *_user_data; + +}; +typedef struct _CleanupData CleanupData; + +static MuResult +_foreach_doc_cb (const char* path, CleanupData *cudata) +{ + if (access (path, R_OK) != 0) { + g_message ("not readable: %s; removing", + path); + /* FIXME: delete from db */ + ++cudata->_stats->_cleaned_up; + } + + if (!cudata->_cb) + return MU_OK; + + return cudata->_cb (cudata->_stats, cudata->_user_data); +} + + +MuResult +mu_index_cleanup (MuIndex *index, MuIndexStats *stats, + MuIndexCleanupDeleteCallback cb, + void *user_data) +{ + MuResult rv; + CleanupData cudata; + + g_return_val_if_fail (index, MU_ERROR); + + cudata._xapian = index->_xapian; + cudata._stats = stats; + cudata._cb = cb; + cudata._user_data = user_data; + + rv = mu_store_xapian_foreach (index->_xapian, + (MuStoreXapianForeachFunc)_foreach_doc_cb, + &cudata); + return rv; } diff --git a/src/mu-index.h b/src/mu-index.h index 89307d8c..2fd7a244 100644 --- a/src/mu-index.h +++ b/src/mu-index.h @@ -34,8 +34,6 @@ struct _MuIndexStats { }; typedef struct _MuIndexStats MuIndexStats; - - /** * create a new MuIndex instance. NOTE(1): the database does not * have to exist yet, but the directory already has to exist;