diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp index fbc3e6e9a4b1ba03eef77d4c74e659130e45be92..33c239d0e1985044f768bf151321e22b413f6db2 100644 --- a/daemon/src/history/historyitem.cpp +++ b/daemon/src/history/historyitem.cpp @@ -51,6 +51,13 @@ const char * const HistoryItem::OUTGOING_STRING = "outgoing"; using std::map; 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), timestampStart_(std::atol(entryMap_[TIMESTAMP_START_KEY].c_str())) {} @@ -65,10 +72,9 @@ HistoryItem::HistoryItem(std::istream &entry) : entryMap_(), timestampStart_(0) else if (pos < tmp.length() - 1) { string key(tmp.substr(0, pos)); string val(tmp.substr(pos + 1, tmp.length() - pos - 1)); - if(key == RECORDING_PATH_KEY && !fexist(val)) - entryMap_[key] = ""; - else - entryMap_[key] = val; + if (key == RECORDING_PATH_KEY and not file_exists(val)) + val = ""; + entryMap_[key] = val; } } timestampStart_ = std::atol(entryMap_[TIMESTAMP_START_KEY].c_str()); @@ -89,18 +95,13 @@ bool HistoryItem::hasPeerNumber() const 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 { // every entry starts with "[" + random integer = "]" for (map<string, string>::const_iterator iter = entryMap_.begin(); iter != entryMap_.end(); ++iter) { // 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; else o << iter->first << "=" << iter->second << std::endl; diff --git a/daemon/src/history/historyitem.h b/daemon/src/history/historyitem.h index e21d834b0543582cd93e23bdc7077039d010b93c..3f7e1e5143215cefc002648cfa81f13cacdc7957 100644 --- a/daemon/src/history/historyitem.h +++ b/daemon/src/history/historyitem.h @@ -59,7 +59,6 @@ class HistoryItem { bool youngerThan(unsigned long otherTime) const; std::map<std::string, std::string> toMap() const; - bool fexist(const std::string &str) const; void print(std::ostream &o) const; bool operator< (const HistoryItem &other) const { return timestampStart_ > other.timestampStart_;