mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-07-23 03:54:24 +08:00
Merge branch 'feature-121-remove-handling-of-read-only-entires'
This commit is contained in:
commit
d0b13bbc8e
@ -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)) {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user