diff --git a/src/dwarfs/util.cpp b/src/dwarfs/util.cpp index 298190808..66055731f 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;