diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 9aef6d4..fc1f005 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -85,18 +85,15 @@ boost::filesystem::path filesystem::get_home_path() noexcept { static boost::filesystem::path home_path; if(!home_path.empty()) return home_path; - std::vector environment_variables = {"HOME", "AppData"}; + std::vector environment_variables = {"HOME", "AppData"}; for(auto &variable : environment_variables) { - if(auto ptr = std::getenv(variable.c_str())) { - boost::system::error_code ec; - boost::filesystem::path path(ptr); - if(boost::filesystem::exists(path, ec)) { - home_path = std::move(path); - return home_path; - } + auto path = get_environment_path(variable); + if(!path.empty()) { + home_path = std::move(path); + break; } } - return boost::filesystem::path(); + return home_path; } bool filesystem::create_missing_path(const boost::filesystem::path &path) noexcept { diff --git a/tests/filesystem_test.cpp b/tests/filesystem_test.cpp index 59539cc..9515752 100644 --- a/tests/filesystem_test.cpp +++ b/tests/filesystem_test.cpp @@ -2,11 +2,6 @@ #include int main() { - { - auto home_path = filesystem::get_home_path(); - g_assert(!home_path.empty()); - } - { auto original = "test () '\""; auto escaped = filesystem::escape_argument(original); @@ -109,4 +104,10 @@ int main() { path = filesystem::get_short_path(path); g_assert(path == "~/.config"); } + + { + auto path = filesystem::get_home_path(); + path = filesystem::get_short_path(path); + g_assert(path == "~"); + } }