diff --git a/src/lib/common/unix/DataDirectories.cpp b/src/lib/common/unix/DataDirectories.cpp index 4f829a9d..72e510af 100644 --- a/src/lib/common/unix/DataDirectories.cpp +++ b/src/lib/common/unix/DataDirectories.cpp @@ -18,14 +18,11 @@ #include "../DataDirectories.h" #include // sysconf +#include // getenv #include // getpwuid(_r) #include // getpwuid(_r) -#ifdef WINAPI_XWINDOWS -const std::string ProfileSubdir = "/.barrier"; -#else // macos -const std::string ProfileSubdir = "/Library/Application Support/Barrier"; -#endif +const std::string ProfileSubdir = "/barrier"; static std::string pw_dir(struct passwd* pwentp) { @@ -61,10 +58,26 @@ static std::string unix_home() #endif // HAVE_GETPWUID_R +static std::string profile_basedir() +{ +#ifdef WINAPI_XWINDOWS + // linux/bsd adheres to freedesktop standards + // https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + const char* dir = getenv("XDG_DATA_HOME"); + if (dir != NULL) + return dir; + return unix_home() + "/.local/share"; +#else + // macos has its own standards + // https://developer.apple.com/library/content/documentation/General/Conceptual/MOSXAppProgrammingGuide/AppRuntime/AppRuntime.html + return unix_home() + "/Library/Application Support"; +#endif +} + const std::string& DataDirectories::profile() { if (_profile.empty()) - _profile = unix_home() + ProfileSubdir; + _profile = profile_basedir() + ProfileSubdir; return _profile; } const std::string& DataDirectories::profile(const std::string& path)