This commit is contained in:
		| @@ -370,7 +370,7 @@ format_path(string_t &path, | |||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
|   if ((path.size() >= 2U) && (path.at(1U) == ':')) { |   if ((path.size() >= 2U) && (path.at(1U) == ':')) { | ||||||
|     path[0U] = utils::string::to_lower(string_t{1U, path.at(0U)}).at(0U); |     path[0U] = utils::string::to_lower(string_t(1U, path.at(0U))).at(0U); | ||||||
|   } |   } | ||||||
| #endif // defined(_WIN32) | #endif // defined(_WIN32) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,8 +41,11 @@ static const std::wstring directory_seperator_str_w{ | |||||||
|       repertory::utils::string::contains(path, "%")) { |       repertory::utils::string::contains(path, "%")) { | ||||||
|     repertory::utils::string::replace(path, "~", "%USERPROFILE%"); |     repertory::utils::string::replace(path, "~", "%USERPROFILE%"); | ||||||
|  |  | ||||||
|  |     auto size = ::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0); | ||||||
|  |     std::cout << size << std::endl; | ||||||
|  |  | ||||||
|     std::string dest; |     std::string dest; | ||||||
|     dest.resize(::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0)); |     dest.resize(size); | ||||||
|     ::ExpandEnvironmentStringsA(path.c_str(), dest.data(), |     ::ExpandEnvironmentStringsA(path.c_str(), dest.data(), | ||||||
|                                 static_cast<DWORD>(dest.size())); |                                 static_cast<DWORD>(dest.size())); | ||||||
|     path = dest.c_str(); |     path = dest.c_str(); | ||||||
| @@ -68,6 +71,9 @@ static const std::wstring directory_seperator_str_w{ | |||||||
| namespace repertory::utils::path { | namespace repertory::utils::path { | ||||||
| auto absolute(std::string_view path) -> std::string { | auto absolute(std::string_view path) -> std::string { | ||||||
|   std::string abs_path{path}; |   std::string abs_path{path}; | ||||||
|  |   abs_path = resolve(abs_path); | ||||||
|  |   format_path(abs_path, directory_seperator, not_directory_seperator); | ||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
|   if (not abs_path.empty() && ::PathIsRelativeA(abs_path.c_str())) { |   if (not abs_path.empty() && ::PathIsRelativeA(abs_path.c_str())) { | ||||||
|     std::string temp; |     std::string temp; | ||||||
| @@ -75,14 +81,14 @@ auto absolute(std::string_view path) -> std::string { | |||||||
|     abs_path = _fullpath(temp.data(), abs_path.c_str(), MAX_PATH); |     abs_path = _fullpath(temp.data(), abs_path.c_str(), MAX_PATH); | ||||||
|   } |   } | ||||||
| #else  // !defined(_WIN32) | #else  // !defined(_WIN32) | ||||||
|   abs_path = resolve(finalize(abs_path)); |  | ||||||
|   if (not abs_path.empty() && (abs_path.at(0U) != '/')) { |   if (not abs_path.empty() && (abs_path.at(0U) != '/')) { | ||||||
|     auto found{false}; |     auto found{false}; | ||||||
|     std::string tmp{abs_path}; |     std::string tmp{abs_path}; | ||||||
|     do { |     do { | ||||||
|       auto *res = realpath(tmp.c_str(), nullptr); |       auto *res = realpath(tmp.c_str(), nullptr); | ||||||
|       if (res) { |       if (res != nullptr) { | ||||||
|         abs_path = combine(res, {abs_path.substr(tmp.size())}); |         abs_path = res + std::string{directory_seperator} + | ||||||
|  |                    abs_path.substr(tmp.size()); | ||||||
|         free(res); |         free(res); | ||||||
|         found = true; |         found = true; | ||||||
|       } else if (tmp == ".") { |       } else if (tmp == ".") { | ||||||
| @@ -94,8 +100,7 @@ auto absolute(std::string_view path) -> std::string { | |||||||
|   } |   } | ||||||
| #endif // defined(_WIN32) | #endif // defined(_WIN32) | ||||||
|  |  | ||||||
|   return format_path(abs_path, get_directory_seperator<char>(), |   return format_path(abs_path, directory_seperator, not_directory_seperator); | ||||||
|                      get_not_directory_seperator<char>()); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| auto absolute(std::wstring_view path) -> std::wstring { | auto absolute(std::wstring_view path) -> std::wstring { | ||||||
|   | |||||||
| @@ -255,7 +255,14 @@ TEST(utils_path, absolute) { | |||||||
|   path = utils::path::absolute("./"); |   path = utils::path::absolute("./"); | ||||||
|   EXPECT_STREQ(dir.c_str(), path.c_str()); |   EXPECT_STREQ(dir.c_str(), path.c_str()); | ||||||
|  |  | ||||||
|   auto home = utils::path::absolute(utils::get_environment_variable("HOME")); | #if defined(_WIN32) | ||||||
|  |   auto home_env = utils::get_environment_variable("USERPROFILE"); | ||||||
|  | #else  // !defined(_WIN32) | ||||||
|  |   auto home_env = utils::get_environment_variable("HOME"); | ||||||
|  | #endif // defined(_WIN32) | ||||||
|  |  | ||||||
|  |   auto home = utils::path::absolute(home_env); | ||||||
|  |  | ||||||
|   path = utils::path::absolute("~"); |   path = utils::path::absolute("~"); | ||||||
|   EXPECT_STREQ(home.c_str(), path.c_str()); |   EXPECT_STREQ(home.c_str(), path.c_str()); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user