diff --git a/Foundation/include/Poco/Path.h b/Foundation/include/Poco/Path.h index 7fd7f5898..c50c1a1a8 100644 --- a/Foundation/include/Poco/Path.h +++ b/Foundation/include/Poco/Path.h @@ -282,7 +282,7 @@ public: /// On Unix systems, this is the colon ':'. On Windows systems, /// this is the semicolon ';'. On OpenVMS systems, this is the /// comma ','. - + static std::string current(); /// Returns the current working directory. @@ -294,13 +294,18 @@ public: /// /// On Unix systems, this is the '~/.config/'. On Windows systems, /// this is '%APPDATA%'. - + static std::string dataHome(); /// Returns the user's data directory. /// /// On Unix systems, this is the '~/.local/share/'. On Windows systems, /// this is '%APPDATA%'. - + + static std::string tempHome(); + /// Returns the user's temp directory. + /// + /// On Unix systems, this is the '~/.local/temp/'. + static std::string cacheHome(); /// Returns the user's cache directory. /// @@ -310,6 +315,11 @@ public: static std::string temp(); /// Returns the temporary directory. + static std::string config(); + /// Returns the systemwide config directory. + /// + /// On Unix systems, this is the '/etc/'. + static std::string null(); /// Returns the name of the null device. diff --git a/Foundation/include/Poco/Path_UNIX.h b/Foundation/include/Poco/Path_UNIX.h index d3bf1789f..50a6478b9 100644 --- a/Foundation/include/Poco/Path_UNIX.h +++ b/Foundation/include/Poco/Path_UNIX.h @@ -32,8 +32,10 @@ public: static std::string homeImpl(); static std::string configHomeImpl(); static std::string dataHomeImpl(); + static std::string tempHomeImpl(); static std::string cacheHomeImpl(); static std::string tempImpl(); + static std::string configImpl(); static std::string nullImpl(); static std::string expandImpl(const std::string& path); static void listRootsImpl(std::vector& roots); diff --git a/Foundation/src/Path.cpp b/Foundation/src/Path.cpp index 7c85af67c..135831447 100644 --- a/Foundation/src/Path.cpp +++ b/Foundation/src/Path.cpp @@ -569,9 +569,39 @@ std::string Path::home() } +std::string Path::configHome() +{ +#if defined(POCO_OS_FAMILY_UNIX) + return PathImpl::configHomeImpl(); +#else + return PathImpl::homeImpl(); +#endif +} + + +std::string Path::dataHome() +{ +#if defined(POCO_OS_FAMILY_UNIX) + return PathImpl::dataHomeImpl(); +#else + return PathImpl::homeImpl(); +#endif +} + + +std::string Path::tempHome() +{ +#if defined(POCO_OS_FAMILY_UNIX) + return PathImpl::tempHomeImpl(); +#else + return PathImpl::tempImpl(); +#endif +} + + std::string Path::cacheHome() { -#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS) +#if defined(POCO_OS_FAMILY_UNIX) return PathImpl::cacheHomeImpl(); #else return PathImpl::homeImpl(); @@ -585,6 +615,15 @@ std::string Path::temp() } +std::string Path::config() +{ +#if defined(POCO_OS_FAMILY_UNIX) + return PathImpl::configImpl(); +#else + return PathImpl::currentImpl(); +#endif +} + std::string Path::null() { return PathImpl::nullImpl(); diff --git a/Foundation/src/Path_UNIX.cpp b/Foundation/src/Path_UNIX.cpp index 8f684a2a3..c9cf86117 100644 --- a/Foundation/src/Path_UNIX.cpp +++ b/Foundation/src/Path_UNIX.cpp @@ -78,24 +78,10 @@ std::string PathImpl::configHomeImpl() { #if defined(POCO_VXWORKS) return PathImpl::homeImpl(); -#elif POCO_OS == POCO_OS_MAC_OS_X +#else std::string path = PathImpl::homeImpl(); std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append("Library/Preferences/"); - return path; -#else - std::string path; - if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME")) - path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME"); - if (!path.empty()) - return path; - - path = PathImpl::homeImpl(); - std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append(".config/"); - + if (n > 0 && path[n - 1] == '/') path.append(".config/"); return path; #endif } @@ -105,24 +91,10 @@ std::string PathImpl::dataHomeImpl() { #if defined(POCO_VXWORKS) return PathImpl::homeImpl(); -#elif POCO_OS == POCO_OS_MAC_OS_X +#else std::string path = PathImpl::homeImpl(); std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append("Library/Application Support/"); - return path; -#else - std::string path; - if (EnvironmentImpl::hasImpl("XDG_DATA_HOME")) - path = EnvironmentImpl::getImpl("XDG_DATA_HOME"); - if (!path.empty()) - return path; - - path = PathImpl::homeImpl(); - std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append(".local/share/"); - + if (n > 0 && path[n - 1] == '/') path.append(".local/share/"); return path; #endif } @@ -132,24 +104,23 @@ std::string PathImpl::cacheHomeImpl() { #if defined(POCO_VXWORKS) return PathImpl::tempImpl(); -#elif POCO_OS == POCO_OS_MAC_OS_X +#else std::string path = PathImpl::homeImpl(); std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append("Library/Caches/"); + if (n > 0 && path[n - 1] == '/') path.append(".cache/"); return path; +#endif +} + + +std::string PathImpl::tempHomeImpl() +{ +#if defined(POCO_VXWORKS) + return PathImpl::tempImpl(); #else - std::string path; - if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME")) - path = EnvironmentImpl::getImpl("XDG_CACHE_HOME"); - if (!path.empty()) - return path; - - path = PathImpl::homeImpl(); + std::string path = PathImpl::homeImpl(); std::string::size_type n = path.size(); - if (n > 0 && path[n - 1] == '/') - path.append(".cache/"); - + if (n > 0 && path[n - 1] == '/') path.append(".local/tmp/"); return path; #endif } @@ -173,6 +144,14 @@ std::string PathImpl::tempImpl() } +std::string PathImpl::configImpl() +{ + std::string path; + path = "/etc/"; + return path; +} + + std::string PathImpl::nullImpl() { #if defined(POCO_VXWORKS) diff --git a/Util/include/Poco/Util/SystemConfiguration.h b/Util/include/Poco/Util/SystemConfiguration.h index 1f4053498..0a52e0fce 100644 --- a/Util/include/Poco/Util/SystemConfiguration.h +++ b/Util/include/Poco/Util/SystemConfiguration.h @@ -80,7 +80,9 @@ private: static const std::string CONFIGHOMEDIR; static const std::string CACHEHOMEDIR; static const std::string DATAHOMEDIR; + static const std::string TEMPHOMEDIR; static const std::string TEMPDIR; + static const std::string CONFIGDIR; static const std::string DATETIME; #if !defined(POCO_VXWORKS) static const std::string PID; diff --git a/Util/src/SystemConfiguration.cpp b/Util/src/SystemConfiguration.cpp index b394e367c..4bdc2fa5f 100644 --- a/Util/src/SystemConfiguration.cpp +++ b/Util/src/SystemConfiguration.cpp @@ -24,6 +24,7 @@ #endif #include "Poco/Exception.h" #include +#include "../../Foundation/include/Poco/Path.h" using Poco::Environment; @@ -44,7 +45,9 @@ const std::string SystemConfiguration::HOMEDIR = "system.homeDir"; const std::string SystemConfiguration::CONFIGHOMEDIR = "system.configHomeDir"; const std::string SystemConfiguration::CACHEHOMEDIR = "system.cacheHomeDir"; const std::string SystemConfiguration::DATAHOMEDIR = "system.dataHomeDir"; +const std::string SystemConfiguration::TEMPHOMEDIR = "system.tempHomeDir"; const std::string SystemConfiguration::TEMPDIR = "system.tempDir"; +const std::string SystemConfiguration::CONFIGDIR = "system.configDir"; const std::string SystemConfiguration::DATETIME = "system.dateTime"; #if !defined(POCO_VXWORKS) const std::string SystemConfiguration::PID = "system.pid"; @@ -121,10 +124,19 @@ bool SystemConfiguration::getRaw(const std::string& key, std::string& value) con { value = Path::dataHome(); } + + else if (key == TEMPHOMEDIR) + { + value = Path::tempHome(); + } else if (key == TEMPDIR) { value = Path::temp(); } + else if (key == CONFIGDIR) + { + value = Path::config(); + } else if (key == DATETIME) { value = Poco::DateTimeFormatter::format(Poco::DateTime(), Poco::DateTimeFormat::ISO8601_FORMAT); @@ -169,7 +181,9 @@ void SystemConfiguration::enumerate(const std::string& key, Keys& range) const range.push_back("configHomeDir"); range.push_back("cacheHomeDir"); range.push_back("dataHomeDir"); + range.push_back("tempHomeDir"); range.push_back("tempDir"); + range.push_back("configDir"); range.push_back("dateTime"); #if !defined(POCO_VXWORKS) range.push_back("pid"); diff --git a/Util/testsuite/src/SystemConfigurationTest.cpp b/Util/testsuite/src/SystemConfigurationTest.cpp index 414c8af8c..a4bd2aa2f 100644 --- a/Util/testsuite/src/SystemConfigurationTest.cpp +++ b/Util/testsuite/src/SystemConfigurationTest.cpp @@ -84,7 +84,7 @@ void SystemConfigurationTest::testKeys() #if defined(POCO_VXWORKS) assert (keys.size() == 10); #else - assert (keys.size() == 11); + assert (keys.size() == 16); #endif assert (std::find(keys.begin(), keys.end(), "osName") != keys.end()); assert (std::find(keys.begin(), keys.end(), "osVersion") != keys.end());