diff --git a/libcxx/src/filesystem/directory_iterator.cpp b/libcxx/src/filesystem/directory_iterator.cpp --- a/libcxx/src/filesystem/directory_iterator.cpp +++ b/libcxx/src/filesystem/directory_iterator.cpp @@ -124,7 +124,8 @@ ec = detail::make_windows_error(GetLastError()); const bool ignore_permission_denied = bool(opts & directory_options::skip_permission_denied); - if (ignore_permission_denied && ec.value() == ERROR_ACCESS_DENIED) + if (ignore_permission_denied && + ec.value() == static_cast(errc::permission_denied)) ec.clear(); return; } diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/path.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/path.pass.cpp --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/path.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/path.pass.cpp @@ -148,6 +148,8 @@ TEST_CASE(path_ctor_cannot_resolve) { using namespace fs; +#ifndef _WIN32 + // Windows doesn't support setting perms::none to trigger failures scoped_test_env env; const path dir = env.create_dir("dir"); const path file = env.create_file("dir/file", 42); @@ -179,6 +181,48 @@ TEST_CHECK_NO_THROW(directory_entry(sym_in_dir)); TEST_CHECK_NO_THROW(directory_entry(sym_out_of_dir)); } +#else + const path dir("C:\\System Volume Information"); + { + std::error_code ec; + const path root("C:\\"); + directory_iterator it(root, ec); + if (ec) + return; + const directory_iterator endIt{}; + bool found = false; + while (it != endIt) { + const directory_entry &ent = *it; + const path &p = *it; + if (p == dir) { + TEST_CHECK(ent.exists()); + TEST_CHECK(ent.is_directory()); + found = true; + break; + } + ++it; + } + if (!found) + return; // No point in proceeding if the directory doesn't exist + } + // We have a dir that exists (in a directory listing), but we can't + // access it (e.g. + { + std::error_code ec = GetTestEC(); + TEST_CHECK(exists(dir, ec) == false); + TEST_CHECK(ErrorIs(ec, std::errc::permission_denied)); + } + const path file = dir / "file"; + { + std::error_code ec = GetTestEC(); + directory_entry ent(file, ec); + TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory)); + TEST_CHECK(ent.path() == file); + } + { + TEST_CHECK_NO_THROW(directory_entry(file)); + } +#endif } TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/ctor.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/ctor.pass.cpp --- a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/ctor.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/ctor.pass.cpp @@ -87,6 +87,9 @@ TEST_CASE(access_denied_test_case) { using namespace fs; +#ifndef _WIN32 + // Windows doesn't support setting perms::none to trigger failures + // reading directories. scoped_test_env env; path const testDir = env.make_env_path("dir1"); path const testFile = testDir / "testFile"; @@ -100,6 +103,31 @@ } // Change the permissions so we can no longer iterate permissions(testDir, perms::none); +#else + const path testDir("C:\\System Volume Information"); + { + std::error_code ec; + const path root("C:\\"); + directory_iterator it(root, ec); + if (ec) + return; + const directory_iterator endIt{}; + bool found = false; + while (it != endIt) { + const directory_entry &ent = *it; + const path &p = *it; + if (p == testDir) { + TEST_CHECK(ent.exists()); + TEST_CHECK(ent.is_directory()); + found = true; + break; + } + ++it; + } + if (!found) + return; // No point in proceeding if the directory doesn't exist + } +#endif // Check that the construction fails when skip_permissions_denied is // not given. diff --git a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp --- a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp @@ -88,6 +88,9 @@ TEST_CASE(access_denied_test_case) { using namespace fs; +#ifndef _WIN32 + // Windows doesn't support setting perms::none to trigger failures + // reading directories. scoped_test_env env; path const testDir = env.make_env_path("dir1"); path const testFile = testDir / "testFile"; @@ -102,6 +105,31 @@ // Change the permissions so we can no longer iterate permissions(testDir, perms::none); +#else + const path testDir("C:\\System Volume Information"); + { + std::error_code ec; + const path root("C:\\"); + directory_iterator it(root, ec); + if (ec) + return; + const directory_iterator endIt{}; + bool found = false; + while (it != endIt) { + const directory_entry &ent = *it; + const path &p = *it; + if (p == testDir) { + TEST_CHECK(ent.exists()); + TEST_CHECK(ent.is_directory()); + found = true; + break; + } + ++it; + } + if (!found) + return; // No point in proceeding if the directory doesn't exist + } +#endif // Check that the construction fails when skip_permissions_denied is // not given. diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp @@ -73,10 +73,17 @@ TEST_CASE(test_exists_fails) { +#ifndef _WIN32 + // Windows doesn't support setting perms::none to trigger failures + // reading directories. scoped_test_env env; const path dir = env.create_dir("dir"); const path file = env.create_file("dir/file", 42); permissions(dir, perms::none); +#else + // Actually a directory, not a file + const path file("C:\\System Volume Information"); +#endif std::error_code ec; TEST_CHECK(exists(file, ec) == false);