Merge branch 'feature-121-remove-handling-of-read-only-entires'

This commit is contained in:
Steffen Schümann 2021-05-23 15:58:55 +02:00
commit d0b13bbc8e
2 changed files with 22 additions and 0 deletions

View File

@ -4649,6 +4649,13 @@ GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept
}
ec = detail::make_system_error(error);
}
else if(attr & FILE_ATTRIBUTE_READONLY) {
auto new_attr = attr & ~static_cast<DWORD>(FILE_ATTRIBUTE_READONLY);
if(!SetFileAttributesW(cstr, new_attr)) {
auto error = ::GetLastError();
ec = detail::make_system_error(error);
}
}
if (!ec) {
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
if (!RemoveDirectoryW(cstr)) {

View File

@ -2889,3 +2889,18 @@ TEST_CASE("Windows: path namespace handling", "[filesystem][path][fs.path.win.na
WARN("Windows specific tests are empty on non-Windows systems.");
#endif
}
TEST_CASE("Windows: Deletion of Read-only Files", "[filesystem][fs.win][fs.win.remove]")
{
#ifdef GHC_OS_WINDOWS
TemporaryDirectory t(TempOpt::change_path);
std::error_code ec;
generateFile("foo", 512);
auto allWrite = fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write;
CHECK_NOTHROW(fs::permissions("foo", allWrite, fs::perm_options::remove));
CHECK_NOTHROW(fs::remove("foo"));
CHECK(!fs::exists("foo"));
#else
WARN("Windows specific tests are empty on non-Windows systems.");
#endif
}