Browse Source

update get home path and test

xdg
Jørgen Lien Sellæg 5 years ago
parent
commit
c2bd161595
  1. 13
      src/filesystem.cpp
  2. 11
      tests/filesystem_test.cpp

13
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<std::string> environment_variables = {"HOME", "AppData"};
std::vector<const char *> 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)) {
auto path = get_environment_path(variable);
if(!path.empty()) {
home_path = std::move(path);
return home_path;
}
break;
}
}
return boost::filesystem::path();
return home_path;
}
bool filesystem::create_missing_path(const boost::filesystem::path &path) noexcept {

11
tests/filesystem_test.cpp

@ -2,11 +2,6 @@
#include <glib.h>
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 == "~");
}
}

Loading…
Cancel
Save