mu: no need to pass 'maildir' when we can deduce it
Only needed when setting up the database.
This commit is contained in:
@ -279,7 +279,7 @@ index_title (MuStore *store, MuConfig *opts)
|
||||
#pragma GCC diagnostic pop
|
||||
g_print ("created : %s%s%s\n", green, tbuf, def);
|
||||
g_print ("maildir : %s%s%s\n",
|
||||
green, mu_store_maildir (store), def);
|
||||
green, mu_store_root_maildir (store), def);
|
||||
|
||||
g_print ("personal-addresses : ");
|
||||
|
||||
|
||||
@ -222,8 +222,6 @@ message_options (const Parameters& params)
|
||||
return (MuMsgOptions)opts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 'add' adds a message to the database, and takes two parameters: 'path', which
|
||||
* is the full path to the message, and 'maildir', which is the maildir this
|
||||
* message lives in (e.g. "/inbox"). response with an (:info ...) message with
|
||||
@ -233,10 +231,9 @@ static void
|
||||
add_handler (Context& context, const Parameters& params)
|
||||
{
|
||||
const auto path{get_string_or(params, "path")};
|
||||
const auto maildir{get_string_or(params, "maildir")};
|
||||
|
||||
GError *gerr{};
|
||||
const auto docid{mu_store_add_path (context.store, path.c_str(), maildir.c_str(), &gerr)};
|
||||
const auto docid{mu_store_add_path (context.store, path.c_str(), &gerr)};
|
||||
if (docid == MU_STORE_INVALID_DOCID)
|
||||
throw Error(Error::Code::Store, &gerr, "failed to add message at %s",
|
||||
path.c_str());
|
||||
@ -1048,9 +1045,7 @@ sent_handler (Context& context, const Parameters& params)
|
||||
{
|
||||
GError *gerr{};
|
||||
const auto path{get_string_or(params, "path")};
|
||||
const auto docid{mu_store_add_path(context.store, path.c_str(),
|
||||
get_string_or(params, "maildir").c_str(),
|
||||
&gerr)};
|
||||
const auto docid{mu_store_add_path(context.store, path.c_str(), &gerr)};
|
||||
if (docid == MU_STORE_INVALID_DOCID)
|
||||
throw Error{Error::Code::Store, &gerr, "failed to add path"};
|
||||
|
||||
@ -1092,8 +1087,7 @@ make_command_map (Context& context)
|
||||
|
||||
cmap.emplace("add",
|
||||
CommandInfo{
|
||||
ArgMap{ {"path", ArgInfo{Type::String, true, "file system path to the message" }},
|
||||
{"maildir", ArgInfo{Type::String, true, "the maildir the where the message lives" }}},
|
||||
ArgMap{ {"path", ArgInfo{Type::String, true, "file system path to the message" }}},
|
||||
"add a message to the store",
|
||||
[&](const auto& params){add_handler(context, params);}});
|
||||
|
||||
|
||||
72
mu/mu-cmd.c
72
mu/mu-cmd.c
@ -374,7 +374,7 @@ foreach_msg_file (MuStore *store, MuConfig *opts,
|
||||
static gboolean
|
||||
add_path_func (MuStore *store, const char *path, GError **err)
|
||||
{
|
||||
return mu_store_add_path (store, path, NULL, err);
|
||||
return mu_store_add_path (store, path, err);
|
||||
}
|
||||
|
||||
|
||||
@ -569,17 +569,37 @@ show_usage (void)
|
||||
typedef MuError (*store_func) (MuStore *, MuConfig *, GError **err);
|
||||
|
||||
|
||||
static gboolean
|
||||
needs_rebuild (MuStore *store, MuConfig *opts, GError **err)
|
||||
static MuStore*
|
||||
get_store (MuConfig *opts, gboolean read_only, GError **err)
|
||||
{
|
||||
if (store)
|
||||
return mu_store_count(store, NULL) == 0;
|
||||
else
|
||||
return err &&
|
||||
(*err)->code == MU_ERROR_XAPIAN_NEEDS_REINDEX &&
|
||||
opts->maildir;
|
||||
if (opts->rebuild && read_only) {
|
||||
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR,
|
||||
"cannot rebuild a read-only database");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (read_only)
|
||||
return mu_store_new_readable (
|
||||
mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), err);
|
||||
|
||||
if (!opts->rebuild)
|
||||
return mu_store_new_writable
|
||||
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), err);
|
||||
|
||||
if (!opts->maildir) {
|
||||
g_set_error (err, MU_ERROR_DOMAIN,
|
||||
MU_ERROR_IN_PARAMETERS,
|
||||
"missing --maildir parameter");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mu_store_new_create (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
|
||||
opts->maildir,
|
||||
(const char**)opts->my_addresses,
|
||||
err);
|
||||
}
|
||||
|
||||
|
||||
static MuError
|
||||
with_store (store_func func, MuConfig *opts, gboolean read_only,
|
||||
GError **err)
|
||||
@ -587,42 +607,10 @@ with_store (store_func func, MuConfig *opts, gboolean read_only,
|
||||
MuStore *store;
|
||||
MuError merr;
|
||||
|
||||
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->maildir, err);
|
||||
}
|
||||
|
||||
store = get_store (opts, read_only, err);
|
||||
if (!store)
|
||||
return MU_G_ERROR_CODE(err);
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user