1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 11:36:07 +00:00

fix: silence "couldn't read file" warnings (#3501)

* fix: silence could not read user-dirs.dirs warning

* fix: silence could not read bandwidth-groups warning
This commit is contained in:
Charles Kerr 2022-07-21 13:22:38 -05:00 committed by GitHub
parent 1eeeb5c152
commit bb3871b8b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 23 deletions

View file

@ -112,6 +112,18 @@ static char const* getHomeDir()
return home; return home;
} }
static std::string xdgConfigHome()
{
if (auto* const dir = tr_env_get_string("XDG_CONFIG_HOME", nullptr); dir != nullptr)
{
auto ret = std::string{ dir };
tr_free(dir);
return ret;
}
return tr_strvPath(getHomeDir(), ".config"sv);
}
void tr_setConfigDir(tr_session* session, std::string_view config_dir) void tr_setConfigDir(tr_session* session, std::string_view config_dir)
{ {
#if defined(__APPLE__) || defined(_WIN32) #if defined(__APPLE__) || defined(_WIN32)
@ -172,17 +184,7 @@ char const* tr_getDefaultConfigDir(char const* appname)
#else #else
char* const xdg_config_home = tr_env_get_string("XDG_CONFIG_HOME", nullptr); s = tr_strvDup(tr_strvPath(xdgConfigHome(), appname));
if (xdg_config_home != nullptr)
{
s = tr_strvDup(tr_strvPath(xdg_config_home, appname));
tr_free(xdg_config_home);
}
else
{
s = tr_strvDup(tr_strvPath(getHomeDir(), ".config", appname));
}
#endif #endif
} }
@ -191,20 +193,11 @@ char const* tr_getDefaultConfigDir(char const* appname)
return s; return s;
} }
static std::string getUserDirsFilename()
{
char* const config_home = tr_env_get_string("XDG_CONFIG_HOME", nullptr);
auto config_file = !tr_str_is_empty(config_home) ? tr_strvPath(config_home, "user-dirs.dirs") :
tr_strvPath(getHomeDir(), ".config", "user-dirs.dirs");
tr_free(config_home);
return config_file;
}
static std::string getXdgEntryFromUserDirs(std::string_view key) static std::string getXdgEntryFromUserDirs(std::string_view key)
{ {
auto content = std::vector<char>{}; auto content = std::vector<char>{};
if (!tr_loadFile(getUserDirsFilename(), content) && std::empty(content)) auto const filename = tr_strvPath(xdgConfigHome(), "user-dirs.dirs"sv);
if (!tr_sys_path_exists(filename) || !tr_loadFile(filename, content) || std::empty(content))
{ {
return {}; return {};
} }

View file

@ -2874,7 +2874,8 @@ static void bandwidthGroupRead(tr_session* session, std::string_view config_dir)
{ {
auto const filename = tr_pathbuf{ config_dir, "/"sv, BandwidthGroupsFilename }; auto const filename = tr_pathbuf{ config_dir, "/"sv, BandwidthGroupsFilename };
auto groups_dict = tr_variant{}; auto groups_dict = tr_variant{};
if (!tr_variantFromFile(&groups_dict, TR_VARIANT_PARSE_JSON, filename, nullptr) || !tr_variantIsDict(&groups_dict)) if (!tr_sys_path_exists(filename) || !tr_variantFromFile(&groups_dict, TR_VARIANT_PARSE_JSON, filename, nullptr) ||
!tr_variantIsDict(&groups_dict))
{ {
return; return;
} }