From 882d7123a7999da34a478128fcf6efb222923c5f Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Mon, 23 Jan 2012 21:46:32 +0000 Subject: [PATCH] Add cache file type to path resolver --- xmltooling/util/PathResolver.cpp | 16 ++++++++++++++++ xmltooling/util/PathResolver.h | 13 +++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/xmltooling/util/PathResolver.cpp b/xmltooling/util/PathResolver.cpp index e241b14..0277e0b 100644 --- a/xmltooling/util/PathResolver.cpp +++ b/xmltooling/util/PathResolver.cpp @@ -38,6 +38,7 @@ PathResolver::PathResolver() : m_defaultPackage(PACKAGE_NAME), m_defaultPrefix(" setXMLDir("/usr/share/xml"); setRunDir("/var/run"); setCfgDir("/etc"); + setCacheDir("/var/cache"); } PathResolver::~PathResolver() @@ -79,6 +80,11 @@ void PathResolver::setCfgDir(const char* dir) m_cfg = dir; } +void PathResolver::setCacheDir(const char* dir) +{ + m_cache = dir; +} + bool PathResolver::isAbsolute(const char* s) const { switch (*s) { @@ -139,6 +145,16 @@ const string& PathResolver::resolve(string& s, file_type_t filetype, const char* } break; + case XMLTOOLING_CACHE_FILE: + s = m_cache + '/' + (pkgname ? pkgname : m_defaultPackage) + '/' + s; + if (!isAbsolute(m_cache.c_str())) { + if (prefix || m_defaultPrefix != "/usr") + s = string(prefix ? prefix : m_defaultPrefix) + '/' + s; + else + s = string("/") + s; + } + break; + default: throw XMLToolingException("Unknown file type to resolve."); } diff --git a/xmltooling/util/PathResolver.h b/xmltooling/util/PathResolver.h index afafb80..3bfb07e 100644 --- a/xmltooling/util/PathResolver.h +++ b/xmltooling/util/PathResolver.h @@ -48,7 +48,8 @@ namespace xmltooling { XMLTOOLING_LOG_FILE, XMLTOOLING_XML_FILE, XMLTOOLING_RUN_FILE, - XMLTOOLING_CFG_FILE + XMLTOOLING_CFG_FILE, + XMLTOOLING_CACHE_FILE }; /** @@ -106,6 +107,14 @@ namespace xmltooling { virtual void setCfgDir(const char* dir); /** + * Set the cache directory to use when resolving files. + *

If relative, the default prefix will be prepended. + * + * @param dir the cache directory to use + */ + virtual void setCacheDir(const char* dir); + + /** * Changes the input filename into an absolute pathname to the same file. * * @param s filename to resolve @@ -120,7 +129,7 @@ namespace xmltooling { private: bool isAbsolute(const char* s) const; - std::string m_defaultPackage,m_defaultPrefix,m_lib,m_log,m_xml,m_run,m_cfg; + std::string m_defaultPackage,m_defaultPrefix,m_lib,m_log,m_xml,m_run,m_cfg,m_cache; }; }; -- 2.1.4