Skip to content
Snippets Groups Projects
Commit 6c664591 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #10304: historyitem: file_exists need not be a member method

parent 9c53f080
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,13 @@ const char * const HistoryItem::OUTGOING_STRING = "outgoing"; ...@@ -51,6 +51,13 @@ const char * const HistoryItem::OUTGOING_STRING = "outgoing";
using std::map; using std::map;
using std::string; using std::string;
namespace {
bool file_exists(const std::string &str)
{
return access(str.c_str(), F_OK) != -1;
}
}
HistoryItem::HistoryItem(const map<string, string> &args) : entryMap_(args), HistoryItem::HistoryItem(const map<string, string> &args) : entryMap_(args),
timestampStart_(std::atol(entryMap_[TIMESTAMP_START_KEY].c_str())) timestampStart_(std::atol(entryMap_[TIMESTAMP_START_KEY].c_str()))
{} {}
...@@ -65,9 +72,8 @@ HistoryItem::HistoryItem(std::istream &entry) : entryMap_(), timestampStart_(0) ...@@ -65,9 +72,8 @@ HistoryItem::HistoryItem(std::istream &entry) : entryMap_(), timestampStart_(0)
else if (pos < tmp.length() - 1) { else if (pos < tmp.length() - 1) {
string key(tmp.substr(0, pos)); string key(tmp.substr(0, pos));
string val(tmp.substr(pos + 1, tmp.length() - pos - 1)); string val(tmp.substr(pos + 1, tmp.length() - pos - 1));
if(key == RECORDING_PATH_KEY && !fexist(val)) if (key == RECORDING_PATH_KEY and not file_exists(val))
entryMap_[key] = ""; val = "";
else
entryMap_[key] = val; entryMap_[key] = val;
} }
} }
...@@ -89,18 +95,13 @@ bool HistoryItem::hasPeerNumber() const ...@@ -89,18 +95,13 @@ bool HistoryItem::hasPeerNumber() const
return entryMap_.find(PEER_NUMBER_KEY) != entryMap_.end(); return entryMap_.find(PEER_NUMBER_KEY) != entryMap_.end();
} }
bool HistoryItem::fexist(const std::string &str) const
{
return access(str.c_str(), F_OK) != -1;
}
void HistoryItem::print(std::ostream &o) const void HistoryItem::print(std::ostream &o) const
{ {
// every entry starts with "[" + random integer = "]" // every entry starts with "[" + random integer = "]"
for (map<string, string>::const_iterator iter = entryMap_.begin(); for (map<string, string>::const_iterator iter = entryMap_.begin();
iter != entryMap_.end(); ++iter) { iter != entryMap_.end(); ++iter) {
// if the file does not exist anymore, we do not save it // if the file does not exist anymore, we do not save it
if(iter->first == RECORDING_PATH_KEY && !fexist(iter->second)) if (iter->first == RECORDING_PATH_KEY and not file_exists(iter->second))
o << iter->first << "=" << "" << std::endl; o << iter->first << "=" << "" << std::endl;
else else
o << iter->first << "=" << iter->second << std::endl; o << iter->first << "=" << iter->second << std::endl;
......
...@@ -59,7 +59,6 @@ class HistoryItem { ...@@ -59,7 +59,6 @@ class HistoryItem {
bool youngerThan(unsigned long otherTime) const; bool youngerThan(unsigned long otherTime) const;
std::map<std::string, std::string> toMap() const; std::map<std::string, std::string> toMap() const;
bool fexist(const std::string &str) const;
void print(std::ostream &o) const; void print(std::ostream &o) const;
bool operator< (const HistoryItem &other) const { bool operator< (const HistoryItem &other) const {
return timestampStart_ > other.timestampStart_; return timestampStart_ > other.timestampStart_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment