From c5dee2c4fb792ea31f24c0aad13dbe23df66941a Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 28 Jan 2012 09:49:09 +0100 Subject: [PATCH] Issue #168 - Configuration cleanup Corrected tokens processing. If directory exist then tokens shall be replaced by correct path, otherwise they are silently removed from path container. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 37 ++++++++++------------- components/files/configurationmanager.hpp | 2 +- components/files/fixedpath.hpp | 20 ------------ 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index e1bf48a6f..91e279051 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -87,27 +87,22 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { const std::string& path = it->string(); - if (!path.empty() && path[0] == '?') + + // Check if path contains a token + if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?') { - std::string::size_type pos = path.find('?', 1); - if (pos != std::string::npos) + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path); + if (tokenIt != mTokensMapping.end()) { - ++pos; - TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos)); + boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); - if (tokenIt != mTokensMapping.end()) + if (boost::filesystem::is_directory(tempPath)) + { + (*it) = tempPath; + } + else { - boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); - - if (boost::filesystem::is_directory(tempPath)) - { - ((mFixedPath).*(tokenIt->second))(tempPath); - (*it) = tempPath; - } - else - { - (*it).clear(); - } + (*it).clear(); } } } diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index dce56ea5d..7d77df9c0 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -44,7 +44,7 @@ struct ConfigurationManager private: typedef Files::FixedPath<> FixedPathType; - typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); + typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3db409b2c..1bf582ab9 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -125,41 +125,21 @@ struct FixedPath return mInstallPath; } - void setInstallPath(const boost::filesystem::path& path) - { - mInstallPath = path; - } - const boost::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; } - void setGlobalDataPath(const boost::filesystem::path& path) - { - mGlobalDataPath = path; - } - const boost::filesystem::path& getUserDataPath() const { return mUserDataPath; } - void setUserDataPath(const boost::filesystem::path& path) - { - mUserDataPath = path; - } - const boost::filesystem::path& getLocalDataPath() const { return mLocalDataPath; } - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; - } - private: PathType mPath;