From 8e32947bdc5940a864fdaaf7bf953f36bafcdf34 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 13 Feb 2024 09:17:29 +0100 Subject: [PATCH] fix: Windows paths suck, really --- src/dwarfs/util.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dwarfs/util.cpp b/src/dwarfs/util.cpp index 29819080..66055731 100644 --- a/src/dwarfs/util.cpp +++ b/src/dwarfs/util.cpp @@ -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;