From 8e07357833582f62170b589aa96ea47320a74a7b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 13 Dec 2021 22:44:58 +0100 Subject: [PATCH 1/3] fix(cli): use $XDG_DATA_HOME instead of $HOME on Linux Follow Freedesktop.org's XDG Base Directory Specification by either using $XDG_DATA_HOME or falling back to ~/.local/share. Ifdef'd to only apply to Linux builds, but could probably safely be enabled on *BSDs by someone more familiar with the prevalence of XDG directories on those platforms. BREAKING CHANGE: This changes the data directory and makes no attempt at falling back to the old one. User data must be manually migrated to the new location if the user wishes to keep it. --- src/cli/utils.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index de17099..f98a444 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -44,7 +44,17 @@ std::string createAndGetAppDir(std::string dir) { if (!std::getenv("HOME")) return ""; home = std::getenv("HOME"); +#ifdef __linux__ + if (!std::getenv("XDG_DATA_HOME")) { + dir = home + "/.local/share/bredbandskollen"; + } else { + std::string xdg_data_home = std::getenv("XDG_DATA_HOME"); + dir = xdg_data_home + "/bredbandskollen"; + } +#else + // Fall back to $HOME for other platforms dir = home + "/.bredbandskollen"; +#endif } int status = mkdir(dir.c_str(), 0755); if (status && errno != EEXIST) { From 35c1c37e6158b04822305701151cb9424efbe2e6 Mon Sep 17 00:00:00 2001 From: Oden Eriksson Date: Fri, 4 Aug 2023 15:52:47 +0200 Subject: [PATCH 2/3] needs the cstdint header --- src/http/httphost.h | 1 + src/http/sha1.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/http/httphost.h b/src/http/httphost.h index e42da3d..336aae8 100644 --- a/src/http/httphost.h +++ b/src/http/httphost.h @@ -4,6 +4,7 @@ #pragma once #include +#include class CookieManager; diff --git a/src/http/sha1.h b/src/http/sha1.h index 96480cf..db53478 100644 --- a/src/http/sha1.h +++ b/src/http/sha1.h @@ -6,6 +6,7 @@ #include #include +#include void base64_encode(const unsigned char *src, size_t len, char *destination); From 449e3935a6a8112c5c86e354c772324e9b238c47 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 18 Jan 2024 01:28:23 +0100 Subject: [PATCH 3/3] fix(cli): create xdg_data_home if it does not exist --- src/cli/utils.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index f98a444..ee67647 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -30,7 +30,7 @@ namespace { } std::string createAndGetAppDir(std::string dir) { - std::string home; + std::string home, xdg_data_home; #ifdef _WIN32 if (dir.empty()) { if (!std::getenv("HOMEDRIVE") || !std::getenv("HOMEPATH")) @@ -46,11 +46,21 @@ std::string createAndGetAppDir(std::string dir) { home = std::getenv("HOME"); #ifdef __linux__ if (!std::getenv("XDG_DATA_HOME")) { - dir = home + "/.local/share/bredbandskollen"; + xdg_data_home = home + "/.local/share"; } else { - std::string xdg_data_home = std::getenv("XDG_DATA_HOME"); - dir = xdg_data_home + "/bredbandskollen"; + xdg_data_home = std::getenv("XDG_DATA_HOME"); } + dir = xdg_data_home + "/bredbandskollen"; + // Make sure xdg_data_home exists + for ( + size_t end = xdg_data_home.find('/', 1), prev = 0; + prev != std::string::npos; + prev = end, end = xdg_data_home.find('/', end+1) + ) { + if(mkdir(xdg_data_home.substr(0, end).c_str(), 0755) && errno != EEXIST) { + return ""; + } + }; #else // Fall back to $HOME for other platforms dir = home + "/.bredbandskollen";