mu-cmd: update for lib/mu-store changes

* some small API updates
 * in with_store, try to rebuild automatically when possible
This commit is contained in:
Dirk-Jan C. Binnema
2019-07-28 14:25:19 +03:00
parent 83d6484f86
commit afde8811b6
8 changed files with 111 additions and 122 deletions

View File

@ -38,7 +38,6 @@
#include "mu-contacts.hh"
#include "mu-runtime.h"
#include "mu-flags.h"
#include "mu-store.h"
#include "mu-log.h"
#define VIEW_TERMINATOR '\f' /* form-feed */
@ -569,31 +568,68 @@ show_usage (void)
typedef MuError (*store_func) (MuStore *, MuConfig *, GError **err);
static gboolean
needs_rebuild (MuStore *store, MuConfig *opts, GError **err)
{
if (store)
return mu_store_count(store, NULL) == 0;
else
return err &&
(*err)->code == MU_ERROR_XAPIAN_NEEDS_REINDEX &&
opts->maildir;
}
static MuError
with_store (store_func func, MuConfig *opts, gboolean read_only,
GError **err)
{
MuStore *store;
MuError merr;
MuError merr;
if (read_only)
store = mu_store_new_read_only
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
err);
else
if (opts->rebuild && read_only) {
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR,
"cannot rebuild a read-only database");
return MU_G_ERROR_CODE(err);
}
if (read_only) {
store = mu_store_new_readable (
mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), err);
} else if (!opts->rebuild) {
store = mu_store_new_writable
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), err);
if (needs_rebuild (store, opts, err)) {
if (store)
mu_store_unref(store);
opts->rebuild = TRUE;
g_clear_error (err);
return with_store(func, opts, read_only, err);
}
} else { /* rebuilding */
if (!opts->maildir) {
g_set_error (err, MU_ERROR_DOMAIN,
MU_ERROR_IN_PARAMETERS,
"missing --maildir parameter");
}
store = mu_store_new_create
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
opts->rebuild, err);
opts->maildir, err);
}
if (!store)
return MU_G_ERROR_CODE(err);
mu_store_set_my_addresses (store, (const char**)opts->my_addresses);
if (!read_only && opts->my_addresses)
mu_store_set_personal_addresses (
store, (const char**)opts->my_addresses);
merr = func (store, opts, err);
mu_store_unref (store);
return merr;
}
static gboolean
check_params (MuConfig *opts, GError **err)
{
@ -607,7 +643,6 @@ check_params (MuConfig *opts, GError **err)
return TRUE;
}
static void
set_log_options (MuConfig *opts)
{
@ -626,7 +661,6 @@ set_log_options (MuConfig *opts)
}
MuError
mu_cmd_execute (MuConfig *opts, GError **err)
{