Skip to content

Commit

Permalink
#106 rmb tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Dec 4, 2017
1 parent f0096b1 commit a08eb67
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
14 changes: 12 additions & 2 deletions src/librmb/rados-dovecot-ceph-cfg-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ namespace librmb {
RadosDovecotCephCfgImpl::RadosDovecotCephCfgImpl(RadosStorage *storage) {
dovecot_cfg = new RadosConfig();
rados_cfg = new RadosCephConfig(storage);
delete_cfg = true;
}

RadosDovecotCephCfgImpl::RadosDovecotCephCfgImpl(RadosConfig *dovecot_cfg_, RadosCephConfig *rados_cfg_) {
dovecot_cfg = dovecot_cfg_;
rados_cfg = rados_cfg_;
// do not delete injected pointer
delete_cfg = false;
}

RadosDovecotCephCfgImpl::~RadosDovecotCephCfgImpl() {
delete dovecot_cfg;
delete rados_cfg;
if (delete_cfg) {
delete dovecot_cfg;
delete rados_cfg;
}
}

int RadosDovecotCephCfgImpl::save_default_rados_config() {
Expand Down
2 changes: 2 additions & 0 deletions src/librmb/rados-dovecot-ceph-cfg-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace librmb {
class RadosDovecotCephCfgImpl : public RadosDovecotCephCfg {
public:
RadosDovecotCephCfgImpl(RadosStorage *storage);
RadosDovecotCephCfgImpl(RadosConfig *dovecot_cfg_, RadosCephConfig *rados_cfg_);
virtual ~RadosDovecotCephCfgImpl();

// dovecot config
Expand Down Expand Up @@ -69,6 +70,7 @@ class RadosDovecotCephCfgImpl : public RadosDovecotCephCfg {
private:
RadosConfig *dovecot_cfg;
RadosCephConfig *rados_cfg;
bool delete_cfg;
};

} /* namespace librmb */
Expand Down
7 changes: 4 additions & 3 deletions src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ std::string RadosMailObject::to_string(const string &padding) {
<< endl;
}

if (flags.length() > 0) {
/* if (flags.length() > 0) {
ss << padding << " " << static_cast<char>(RBOX_METADATA_OLDV1_FLAGS)
<< "(flags): " << RadosUtils::string_to_flags(flags) << endl;
}

}*/
/*
if (pvt_flags.length() > 0) {
ss << padding << " " << static_cast<char>(RBOX_METADATA_PVT_FLAGS) << "(private flags): " << pvt_flags
<< endl;
}
*/
if (from_envelope.length() > 0) {
ss << padding << " " << static_cast<char>(RBOX_METADATA_FROM_ENVELOPE)
<< "(from envelope): " << from_envelope << endl;
Expand Down
25 changes: 16 additions & 9 deletions src/librmb/tools/rmb/rmb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static void usage(std::ostream &out) {
" specify the namespace/user to use for the mails\n"
" -O path to store the boxes. If not given, $HOME/rmb is used\n"
" lspools list pools\n "
" -help print this information\n"
"\n"
"\nMAIL COMMANDS\n"
" ls - list all mails and mailbox statistic\n"
Expand Down Expand Up @@ -345,6 +346,7 @@ int main(int argc, const char **argv) {
bool is_config = false;
bool create_config = false;
bool update_confirmed = false;
bool show_usage = false;
argv_to_vec(argc, argv, &args);

for (i = args.begin(); i != args.end();) {
Expand Down Expand Up @@ -372,6 +374,8 @@ int main(int argc, const char **argv) {
opts["update"] = val;
} else if (ceph_argparse_flag(args, i, "-C", "--create", (char *)NULL)) {
create_config = true;
} else if (ceph_argparse_flag(args, i, "-help", "--help", (char *)NULL)) {
show_usage = true;
} else if (ceph_argparse_flag(args, i, "-yes-i-really-really-mean-it", "--yes-i-really-really-mean-it",
(char *)NULL)) {
update_confirmed = true;
Expand All @@ -386,6 +390,10 @@ int main(int argc, const char **argv) {
}
}

if (show_usage) {
usage_exit();
}

if (args.size() <= 0 && opts.size() <= 0 && !is_config) {
usage_exit();
}
Expand Down Expand Up @@ -425,6 +433,11 @@ int main(int argc, const char **argv) {
return -1;
}

librmb::RadosCephConfig ceph_cfg(&storage);
std::string obj_ = opts.find("cfg_obj") != opts.end() ? opts["cfg_obj"] : ceph_cfg.get_cfg_object_name();
ceph_cfg.set_cfg_object_name(obj_);
ceph_cfg.set_config_valid(true);

if (is_config) {
// std::cout << "found cfg: " << opts["cfg_obj"] << " " << opts["update"] << " " << opts["ls"] << "\n";
bool has_update = opts.find("update") != opts.end();
Expand All @@ -433,11 +446,7 @@ int main(int argc, const char **argv) {
usage_exit();
}

librmb::RadosCephConfig ceph_cfg(&storage);
std::string obj_ = opts.find("cfg_obj") != opts.end() ? opts["cfg_obj"] : ceph_cfg.get_cfg_object_name();


ceph_cfg.set_cfg_object_name(obj_);
if (ceph_cfg.load_cfg() < 0) {
int ret = 0;
if (create_config) {
Expand Down Expand Up @@ -496,11 +505,10 @@ int main(int argc, const char **argv) {
cluster.deinit();
return 0;
}

librmb::RadosDovecotCephCfgImpl cfg(&storage);
librmb::RadosConfig dovecot_cfg;
dovecot_cfg.set_config_valid(true);
librmb::RadosDovecotCephCfgImpl cfg(&dovecot_cfg, &ceph_cfg);
librmb::RadosNamespaceManager mgr(&storage, &cfg);
cfg.set_generated_namespace(true);
cfg.set_config_valid(true);
if (opts.find("namespace") == opts.end()) {
cluster.deinit();
usage_exit();
Expand All @@ -512,7 +520,6 @@ int main(int argc, const char **argv) {
storage.set_namespace(ns);
} else {
// use
cfg.set_generated_namespace(false);
if (!mgr.lookup_key(uid, &ns)) {
std::cout << " error unable to determine namespace" << std::endl;
return -1;
Expand Down

0 comments on commit a08eb67

Please sign in to comment.