diff --git a/src/librmb/tools/rmb/rmb-commands.cpp b/src/librmb/tools/rmb/rmb-commands.cpp index affd6af1..b37d2dfe 100644 --- a/src/librmb/tools/rmb/rmb-commands.cpp +++ b/src/librmb/tools/rmb/rmb-commands.cpp @@ -131,11 +131,39 @@ int RmbCommands::lspools() { return 0; } +int RmbCommands::delete_namespace(librmb::RadosStorageMetadataModule *ms, + std::vector &mail_objects, librmb::RadosCephConfig *cfg, + bool confirmed) { + librmb::CmdLineParser parser("-"); + if(parser.parse_ls_string()){ + std::string sort_type = "uid"; + int ret = load_objects(ms, mail_objects, sort_type); + if (ret < 0 || mail_objects.size() == 0) { + return ret; + } + + for (std::vector::iterator it_mail = mail_objects.begin(); it_mail != mail_objects.end(); + ++it_mail) { + (*opts)["to_delete"] = (*it_mail)->get_oid(); + delete_mail(confirmed); + } + if (cfg->is_user_mapping()) { + // delete namespace object also. + std::cout << "user mapping active " << std::endl; + std::string indirect_ns = (*opts)["namespace"] + cfg->get_user_suffix(); + (*opts)["to_delete"] = indirect_ns; + storage->set_namespace("users"); + delete_mail(confirmed); + } + } + return 0; +} int RmbCommands::delete_mail(bool confirmed) { int ret = -1; print_debug("entry: delete_mail"); if (!confirmed) { - std::cout << "WARNING: Deleting a mail object will remove the object from ceph, but not from dovecot index, this " + std::cout << "WARNING: Deleting a mail object will remove the " + "object from ceph, but not from dovecot index, this " "may lead to corrupt mailbox\n" << " add --yes-i-really-really-mean-it to confirm the delete " << std::endl; } else { diff --git a/src/librmb/tools/rmb/rmb-commands.h b/src/librmb/tools/rmb/rmb-commands.h index cf1ea5e2..d9670704 100644 --- a/src/librmb/tools/rmb/rmb-commands.h +++ b/src/librmb/tools/rmb/rmb-commands.h @@ -44,6 +44,8 @@ class RmbCommands { void print_debug(const std::string &msg); static int lspools(); int delete_mail(bool confirmed); + int delete_namespace(librmb::RadosStorageMetadataModule *ms, std::vector &mail_objects, + librmb::RadosCephConfig *cfg, bool confirmed); int rename_user(librmb::RadosCephConfig *cfg, bool confirmed, const std::string &uid); diff --git a/src/librmb/tools/rmb/rmb.cpp b/src/librmb/tools/rmb/rmb.cpp index b4e6a5fc..67b0c29d 100644 --- a/src/librmb/tools/rmb/rmb.cpp +++ b/src/librmb/tools/rmb/rmb.cpp @@ -389,13 +389,24 @@ int main(int argc, const char **argv) { std::cerr << " Error initializing metadata module " << std::endl; delete rmb_commands; release_exit(&mail_objects, &cluster, false); + exit(0); } if (delete_mail_option) { - if (rmb_commands->delete_mail(confirmed) < 0) { - std::cerr << "error deleting mail" << std::endl; - cluster.deinit(); + if (opts["to_delete"].size() == 1 && opts["to_delete"].compare("-") == 0) { + if (rmb_commands->delete_namespace(ms, mail_objects, &ceph_cfg, confirmed) < 0) { + std::cerr << "error deleting namespace " << std::endl; + release_exit(&mail_objects, &cluster, false); + } + } else { + if (rmb_commands->delete_mail(confirmed) < 0) { + std::cerr << "error deleting mail" << std::endl; + } } + release_exit(&mail_objects, &cluster, false); + delete rmb_commands; + delete ms; + exit(0); } else if (rename_user_option) { if (rmb_commands->rename_user(&ceph_cfg, confirmed, uid) < 0) { @@ -423,6 +434,7 @@ int main(int argc, const char **argv) { delete rmb_commands; delete ms; + // tear down. release_exit(&mail_objects, &cluster, false); }