diff options
author | Martin Braun <martin.braun@ettus.com> | 2020-03-05 16:23:07 -0800 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-04-02 12:36:20 -0500 |
commit | 1383fde3457168ed759d6ed3b913dfae8a6085ef (patch) | |
tree | 60acf5dfd0a917e6fcc562005dd2405332e1f8bb /host/lib/utils/prefs.cpp | |
parent | c65166562f1278f6633b183b7188789158210544 (diff) | |
download | uhd-1383fde3457168ed759d6ed3b913dfae8a6085ef.tar.gz uhd-1383fde3457168ed759d6ed3b913dfae8a6085ef.tar.bz2 uhd-1383fde3457168ed759d6ed3b913dfae8a6085ef.zip |
uhd: paths: Harmonize around XDG Base Directory specification
Up until now, we completely ignore the XDG specification.
This commit does the following to change that:
- It uses XDG_DATA_HOME and XDG_CONFIG_HOME for cal and config data,
respectively.
- If config data is in ~/.uhd/uhd.conf, that is still accepted, but if
it conflicts with $XDG_CONFIG_HOME/uhd.conf, it is ignored and a
warning is displayed
- The default location for cal data is thus ${HOME}/.local/share/uhd/cal
on Unix, and %LOCALAPPDATA%\uhd\cal on Windows. This is a change in
location!
- The UHD_CONFIG_DIR environment variable was confusingly named and is
now removed. It provided an alternative location than the home
directory. The same purpose is now much better served by XDG_DATA_HOME
and XDG_CONFIG_HOME.
The specification can be found here:
specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Diffstat (limited to 'host/lib/utils/prefs.cpp')
-rw-r--r-- | host/lib/utils/prefs.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/host/lib/utils/prefs.cpp b/host/lib/utils/prefs.cpp index 72a9c9eea..58c47f730 100644 --- a/host/lib/utils/prefs.cpp +++ b/host/lib/utils/prefs.cpp @@ -17,7 +17,7 @@ using namespace uhd; namespace { constexpr char UHD_CONF_FILE_VAR[] = "UHD_CONFIG_FILE"; -inline void _update_conf_file( +inline bool _update_conf_file( const std::string& path, const std::string& config_type, config_parser& conf_file) { if (not path.empty()) { @@ -27,15 +27,19 @@ inline void _update_conf_file( conf_file.read_file(path); UHD_LOG_DEBUG( "PREFS", "Loaded " << config_type << " config file " << path); + return true; } catch (...) { UHD_LOG_DEBUG( "PREFS", "Failed to load " << config_type << " config file " << path); + return false; } } else { UHD_LOG_TRACE( "PREFS", "No " << config_type << " config file found at " << path); + return false; } } + return false; } void update_from_key( @@ -76,10 +80,26 @@ config_parser& uhd::prefs::get_uhd_config() UHD_LOG_TRACE("CONF", "Initializing config file object..."); const std::string sys_conf_file = path_expandvars(UHD_SYS_CONF_FILE); _update_conf_file(sys_conf_file, "system", _conf_files); + // prefer .config/uhd.conf + // otherwise ~/.uhd/uhd.conf const std::string user_conf_file = - (boost::filesystem::path(get_app_path()) / std::string(UHD_USER_CONF_FILE)) - .string(); - _update_conf_file(user_conf_file, "user", _conf_files); + (get_xdg_config_home() / std::string(UHD_USER_CONF_FILE)).string(); + const bool user_conf_loaded = + _update_conf_file(user_conf_file, "user", _conf_files); + // Config files can be in ~/.config/ or in ~/.uhd. The latter is + // considered deprecated. We load from there (if we have not already + // loaded from ~/.config), but we show a warning. + if (!user_conf_loaded + && _update_conf_file( + (get_legacy_config_home() / std::string(UHD_USER_CONF_FILE)).string(), + "user", + _conf_files)) { + UHD_LOG_WARNING("PREFS", + "Loaded config from " << get_legacy_config_home().string() + << ". This location is considered deprecated, " + "consider moving your config file to " + << get_xdg_config_home().string() << " instead."); + } std::string env_conf_file; try { // getenv into std::string can fail if (std::getenv(UHD_CONF_FILE_VAR) != NULL) { |