From ff7b6338a08cea61cdcebfdeb3d20a7ac7ce5a09 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 07:21:18 +0100 Subject: [PATCH] Replace `Poco::Path::dataHome()` with `get_data_home()`. `Poco::Path::dataHome()` does not follow the XDG Base Directory Specification. --- include/sqlite.hpp | 2 ++ src/lib/sqlite.cpp | 38 +++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/sqlite.hpp b/include/sqlite.hpp index bb2b6d1..d341683 100644 --- a/include/sqlite.hpp +++ b/include/sqlite.hpp @@ -111,6 +111,8 @@ private: fs::path _dbpath; std::unique_ptr _session; bool _connected; + + fs::path get_data_home() const; }; } // namespace remwharead diff --git a/src/lib/sqlite.cpp b/src/lib/sqlite.cpp index 12de60f..65b68e4 100644 --- a/src/lib/sqlite.cpp +++ b/src/lib/sqlite.cpp @@ -19,11 +19,7 @@ #include #include #include -#if POCO_VERSION >= 0x01090000 // Path::dataHome() is only in 1.9 and above. -#include -#else #include -#endif #include #include #include @@ -34,30 +30,14 @@ using std::cerr; using std::endl; using namespace Poco::Data::Keywords; using Poco::Data::Statement; -#if POCO_VERSION < 0x01090000 using Poco::Environment; -#endif Database::Database() : _connected(false) { try { - #if POCO_VERSION >= 0x01090000 - _dbpath = Poco::Path::dataHome() / fs::path("remwharead"); - #else - if (Environment::has("XDG_DATA_HOME")) - { - _dbpath = Environment::get("XDG_DATA_HOME") - / fs::path("remwharead"); - } - else if (Environment::has("HOME")) - { - _dbpath = Environment::get("HOME") - / fs::path(".local/share/remwharead"); - } // Else use current directory. - #endif - + _dbpath = get_data_home(); if (!fs::exists(_dbpath)) { fs::create_directories(_dbpath); @@ -185,4 +165,20 @@ list Database::retrieve(const time_point &start, return {}; } + +fs::path Database::get_data_home() const +{ + fs::path path; + + if (Environment::has("XDG_DATA_HOME")) + { + path = Environment::get("XDG_DATA_HOME") / fs::path("remwharead"); + } + else if (Environment::has("HOME")) + { + path = Environment::get("HOME") / fs::path(".local/share/remwharead"); + } // Else return empty path. + + return path; +} } // namespace remwharead