mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-11 02:36:33 +08:00
refs #121, allow fs::remove on read-only entries in windows too
This commit is contained in:
parent
e65a6baf76
commit
a697b05dd7
@ -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 & ~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