Replace `Poco::Path::dataHome()` with `get_data_home()`.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
`Poco::Path::dataHome()` does not follow the XDG Base Directory Specification.
This commit is contained in:
parent
253047c0b5
commit
ff7b6338a0
|
@ -111,6 +111,8 @@ private:
|
||||||
fs::path _dbpath;
|
fs::path _dbpath;
|
||||||
std::unique_ptr<Session> _session;
|
std::unique_ptr<Session> _session;
|
||||||
bool _connected;
|
bool _connected;
|
||||||
|
|
||||||
|
fs::path get_data_home() const;
|
||||||
};
|
};
|
||||||
} // namespace remwharead
|
} // namespace remwharead
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,7 @@
|
||||||
#include <Poco/Data/SQLite/Connector.h>
|
#include <Poco/Data/SQLite/Connector.h>
|
||||||
#include <Poco/Data/Session.h>
|
#include <Poco/Data/Session.h>
|
||||||
#include <Poco/Version.h>
|
#include <Poco/Version.h>
|
||||||
#if POCO_VERSION >= 0x01090000 // Path::dataHome() is only in 1.9 and above.
|
|
||||||
#include <Poco/Path.h>
|
|
||||||
#else
|
|
||||||
#include <Poco/Environment.h>
|
#include <Poco/Environment.h>
|
||||||
#endif
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -34,30 +30,14 @@ using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using namespace Poco::Data::Keywords;
|
using namespace Poco::Data::Keywords;
|
||||||
using Poco::Data::Statement;
|
using Poco::Data::Statement;
|
||||||
#if POCO_VERSION < 0x01090000
|
|
||||||
using Poco::Environment;
|
using Poco::Environment;
|
||||||
#endif
|
|
||||||
|
|
||||||
Database::Database()
|
Database::Database()
|
||||||
: _connected(false)
|
: _connected(false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if POCO_VERSION >= 0x01090000
|
_dbpath = get_data_home();
|
||||||
_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
|
|
||||||
|
|
||||||
if (!fs::exists(_dbpath))
|
if (!fs::exists(_dbpath))
|
||||||
{
|
{
|
||||||
fs::create_directories(_dbpath);
|
fs::create_directories(_dbpath);
|
||||||
|
@ -185,4 +165,20 @@ list<Database::entry> Database::retrieve(const time_point &start,
|
||||||
|
|
||||||
return {};
|
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
|
} // namespace remwharead
|
||||||
|
|
Loading…
Reference in New Issue