Avoid calling Boost logging functions in appdata()

The app data directory is needed prior to logging initialization.
This commit is contained in:
Cameron Gutman
2024-03-15 00:11:02 -05:00
parent f66a7d5da6
commit aa1985dec8

View File

@@ -10,6 +10,7 @@
// standard includes // standard includes
#include <fstream> #include <fstream>
#include <iostream>
// lib includes // lib includes
#include <arpa/inet.h> #include <arpa/inet.h>
@@ -98,6 +99,11 @@ namespace platf {
return ifaddr_t { p }; return ifaddr_t { p };
} }
/**
* @brief Performs migration if necessary, then returns the appdata directory.
* @details This is used for the log directory, so it cannot invoke Boost logging!
* @return The path of the appdata directory that should be used.
*/
fs::path fs::path
appdata() { appdata() {
bool found = false; bool found = false;
@@ -136,15 +142,18 @@ namespace platf {
fs::path old_config_path = fs::path(homedir) / ".config/sunshine"sv; fs::path old_config_path = fs::path(homedir) / ".config/sunshine"sv;
if (old_config_path != config_path && fs::exists(old_config_path)) { if (old_config_path != config_path && fs::exists(old_config_path)) {
if (!fs::exists(config_path)) { if (!fs::exists(config_path)) {
BOOST_LOG(info) << "Migrating config from "sv << old_config_path << " to "sv << config_path; std::cout << "Migrating config from "sv << old_config_path << " to "sv << config_path << std::endl;
std::error_code ec; std::error_code ec;
fs::rename(old_config_path, config_path, ec); fs::rename(old_config_path, config_path, ec);
if (ec) { if (ec) {
std::cerr << "Migration failed: " << ec.message() << std::endl;
return old_config_path; return old_config_path;
} }
} }
else { else {
BOOST_LOG(warning) << "Config exists in both "sv << old_config_path << " and "sv << config_path << ", using "sv << config_path << "... it is recommended to remove "sv << old_config_path; // We cannot use Boost logging because it hasn't been initialized yet!
std::cerr << "Config exists in both "sv << old_config_path << " and "sv << config_path << ". Using "sv << config_path << " for config" << std::endl;
std::cerr << "It is recommended to remove "sv << old_config_path << std::endl;
} }
} }
} }