From 88f03acfbf0ab4dfaf866d667652fe5429d176a0 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sat, 5 Jul 2025 23:47:20 -0500 Subject: [PATCH] Resolve symlinks when getting configuration file paths --- server/driver/configuration.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 7bcd7a0f..ea27e56a 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -36,9 +36,21 @@ #include "utils/xdg_base_directory.h" #include "wivrn_config.h" +static auto resolve_path(std::filesystem::path path) +{ + std::error_code ec; + auto canonical = std::filesystem::canonical(path, ec); + + // path doesn't exist + if (ec) + return path; + + return canonical; +} + static std::filesystem::path config_file; -static std::filesystem::path known_keys_file = xdg_config_home() / "wivrn" / "known_keys.json"; -static std::filesystem::path cookie_file = xdg_config_home() / "wivrn" / "cookie"; +static std::filesystem::path known_keys_file = resolve_path(xdg_config_home() / "wivrn" / "known_keys.json"); +static std::filesystem::path cookie_file = resolve_path(xdg_config_home() / "wivrn" / "cookie"); namespace wivrn { @@ -65,12 +77,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM( void configuration::set_config_file(const std::filesystem::path & path) { - config_file = path; + config_file = resolve_path(path); } std::filesystem::path configuration::get_config_file() { if (config_file.empty()) - return xdg_config_home() / "wivrn" / "config.json"; + return resolve_path(xdg_config_home() / "wivrn" / "config.json"); return config_file; } @@ -85,7 +97,7 @@ nlohmann::json configuration::read_configuration() xdg_config_home(), }) { - auto path = prefix / "wivrn" / "config.json"; + auto path = resolve_path(prefix / "wivrn" / "config.json"); if (std::filesystem::exists(path)) { try