fix: Windows paths suck, really

This commit is contained in:
Marcus Holland-Moritz 2024-02-13 09:17:29 +01:00
parent b136bbaf86
commit 8e32947bdc

View File

@ -306,15 +306,17 @@ void shorten_path_string(std::string& path, char separator, size_t max_len) {
std::filesystem::path canonical_path(std::filesystem::path p) {
if (!p.empty()) {
#ifdef _WIN32
p = std::filesystem::path(L"\\\\?\\" + p.wstring());
#endif
try {
p = std::filesystem::canonical(p);
} catch (std::filesystem::filesystem_error const&) {
p = std::filesystem::absolute(p);
}
#ifdef _WIN32
if (auto wstr = p.wstring(); !wstr.starts_with(L"\\\\")) {
p = std::filesystem::path(L"\\\\?\\" + wstr);
}
#endif
}
return p;