From 3fd3482559dfd925ec8df54b8cc6b3b11f469078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Sch=C3=BCmann?= Date: Sun, 8 Nov 2020 11:11:35 +0100 Subject: [PATCH] refs #75, fix for windows path filtering on namespaces --- include/ghc/filesystem.hpp | 21 +++++++++------------ test/filesystem_test.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index f1f05f1..82f6d84 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1257,7 +1257,6 @@ class GHC_FS_API_CLASS u8arguments //------------------------------------------------------------------------------------------------- namespace detail { -// GHC_FS_API void postprocess_path_with_format(path::impl_string_type& p, path::format fmt); enum utf8_states_t { S_STRT = 0, S_RJCT = 8 }; GHC_FS_API void appendUTF8(std::string& str, uint32_t unicode); GHC_FS_API bool is_surrogate(uint32_t c); @@ -1654,17 +1653,15 @@ GHC_INLINE void path::postprocess_path_with_format(path::impl_string_type& p, pa #ifdef GHC_OS_WINDOWS case path::auto_format: case path::native_format: - if (p.length() > 4 && p[2] == '?') { - if (detail::startsWith(p, std::string("\\\\?\\"))) { - // remove Windows long filename marker - p.erase(0, 4); - if (detail::startsWith(p, std::string("UNC\\"))) { - p.erase(0, 2); - p[0] = '\\'; + if (p.length() >= 4 && p[2] == '?') { + if (p.length() == 4 || (p.length() >= 6 && p[5] == ':')) { + if (detail::startsWith(p, std::string("\\\\?\\"))) { + // remove Windows long filename marker for simple paths + p.erase(0, 4); + } + else if (detail::startsWith(p, std::string("\\??\\"))) { + p.erase(0, 4); } - } - else if (detail::startsWith(p, std::string("\\??\\"))) { - p.erase(0, 4); } } for (auto& c : p) { @@ -2554,7 +2551,7 @@ GHC_INLINE path::impl_string_type path::native_impl() const if (is_absolute() && _path.length() > MAX_PATH - 10) { // expand long Windows filenames with marker if (has_root_name() && _path[0] == '/') { - result = "\\\\?\\UNC" + _path.substr(1); + result = "\\\\?\\" + _path.substr(1); } else { result = "\\\\?\\" + _path; diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index cb451d9..985a0c9 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -1941,6 +1941,11 @@ TEST_CASE("30.10.15.13 exists", "[filesystem][operations][fs.op.exists]") ec = std::error_code(42, std::system_category()); CHECK(fs::exists(t.path(), ec)); CHECK(!ec); +#if defined(GHC_OS_WINDOWS) && !defined(GHC_FILESYSTEM_FWD) + if (::GetFileAttributesW(L"C:\\fs-test") != INVALID_FILE_ATTRIBUTES) { + CHECK(fs::exists("C:\\fs-test")); + } +#endif } TEST_CASE("30.10.15.14 file_size", "[filesystem][operations][fs.op.file_size]") @@ -2729,7 +2734,7 @@ TEST_CASE("Windows: Long filename support", "[filesystem][path][fs.path.win.long #endif } -TEST_CASE("Windows: UNC path support", "[filesystem][path][fs.path.win.unc]") +TEST_CASE("Windows: path namespace support", "[filesystem][path][fs.path.win.namespaces]") { #ifdef GHC_OS_WINDOWS std::error_code ec;