Skip to content

Commit

Permalink
Merge pull request #173 from ceph-dovecot/20180711_jrse#171
Browse files Browse the repository at this point in the history
#171: supports rmb -u <user> delete - --yes-i-really-really-mean-it
  • Loading branch information
jrse authored Jul 16, 2018
2 parents 43feaec + f1a3aa6 commit 7a74201
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/librmb/tools/rmb/rmb-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,39 @@ int RmbCommands::lspools() {
return 0;
}

int RmbCommands::delete_namespace(librmb::RadosStorageMetadataModule *ms,
std::vector<librmb::RadosMailObject *> &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<librmb::RadosMailObject *>::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 {
Expand Down
2 changes: 2 additions & 0 deletions src/librmb/tools/rmb/rmb-commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<librmb::RadosMailObject *> &mail_objects,
librmb::RadosCephConfig *cfg, bool confirmed);

int rename_user(librmb::RadosCephConfig *cfg, bool confirmed, const std::string &uid);

Expand Down
18 changes: 15 additions & 3 deletions src/librmb/tools/rmb/rmb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -423,6 +434,7 @@ int main(int argc, const char **argv) {

delete rmb_commands;
delete ms;

// tear down.
release_exit(&mail_objects, &cluster, false);
}
Expand Down

0 comments on commit 7a74201

Please sign in to comment.