Skip to content

Commit

Permalink
refs #75, fix for windows path filtering on namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Nov 8, 2020
1 parent cf78907 commit 3fd3482
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 9 additions & 12 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3fd3482

Please sign in to comment.