From 6c664591b8acfc65ece84be88000caf05f58e9f6 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 29 May 2012 11:19:22 -0400 Subject: [PATCH] * #10304: historyitem: file_exists need not be a member method --- daemon/src/history/historyitem.cpp | 21 +++++++++++---------- daemon/src/history/historyitem.h | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp index fbc3e6e9a4..33c239d0e1 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 e21d834b05..3f7e1e5143 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_; -- GitLab