Skip to content

Commit

Permalink
#142: fix sort
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed May 23, 2018
1 parent 7608f2b commit 3eb10da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/librmb/tools/rmb/rmb-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,43 @@ int RmbCommands::configuration(bool confirmed, librmb::RadosCephConfig &ceph_cfg
bool RmbCommands::sort_uid(librmb::RadosMailObject *i, librmb::RadosMailObject *j) {
std::string::size_type sz; // alias of size_t
std::string t = i->get_metadata(librmb::RBOX_METADATA_MAIL_UID);
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_MAIL_UID), &sz);
return i_uid < j_uid;
try {
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_MAIL_UID), &sz);
return i_uid < j_uid;
} catch (std::exception &e) {
std::cerr << " sort_uid: " << t << "(" << i->get_oid() << ") or " << j->get_metadata(librmb::RBOX_METADATA_MAIL_UID)
<< " (" << j->get_oid() << ") is not a number" << std::endl;
return false;
}
}

bool RmbCommands::sort_recv_date(librmb::RadosMailObject *i, librmb::RadosMailObject *j) {
std::string::size_type sz; // alias of size_t
std::string t = i->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME);
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), &sz);
return i_uid < j_uid;
try {
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), &sz);
return i_uid < j_uid;
} catch (std::exception &e) {
std::cerr << " sort_recv_date: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME)
<< " is not a number" << std::endl;
return false;
}
}

bool RmbCommands::sort_phy_size(librmb::RadosMailObject *i, librmb::RadosMailObject *j) {
std::string::size_type sz; // alias of size_t
std::string t = i->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE);
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), &sz);
return i_uid < j_uid;
try {
long i_uid = std::stol(t, &sz);
long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), &sz);
return i_uid < j_uid;
} catch (std::exception &e) {
std::cerr << " sort_physical_size: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE)
<< " is not a number" << std::endl;
return false;
}
}

bool RmbCommands::sort_save_date(librmb::RadosMailObject *i, librmb::RadosMailObject *j) {
Expand Down Expand Up @@ -273,7 +291,6 @@ int RmbCommands::print_mail(std::map<std::string, librmb::RadosMailBox *> *mailb
std::cout << " error initializing output dir : " << output_dir << std::endl;
break;
}

for (std::vector<librmb::RadosMailObject *>::iterator it_mail = it->second->get_mails().begin();
it_mail != it->second->get_mails().end(); ++it_mail) {
const std::string oid = (*it_mail)->get_oid();
Expand Down
5 changes: 4 additions & 1 deletion src/storage-rbox/rbox-mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,11 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s
return -1;
}
} else if (physical_size == 0) {
i_warning("trying to read a mail (size = 0) which is currently copied, moved or stored, returning with error. ");
i_error(
"trying to read a mail (size = 0) which is currently copied, moved or stored, returning with error. "
"expunging mail");
FUNC_END_RET("ret == 0");
rbox_mail_set_expunged(rmail);
return -1;
} else if (physical_size == INT_MAX) {
i_error("trying to read a mail with INT_MAX size. ");
Expand Down

0 comments on commit 3eb10da

Please sign in to comment.