Skip to content

Commit 816d114

Browse files
committed
Fix problem with shutil.rmtree if emulating Windows under POSIX
- the fd functions that are used for rmtree are not available under Windows -> switched of the usage of these function in the fake fs - fixes #979
1 parent 67e3a56 commit 816d114

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The released versions correspond to PyPI releases.
2323
* fixed handling of `dirfd` in `os.symlink` (see [#968](../../issues/968))
2424
* add missing `follow_symlink` argument to `os.link` (see [#973](../../issues/973))
2525
* fixed handling of missing attribute in `os.getxattr` (see [#971](../../issues/971))
26+
* fixed permission problem with `shutil.rmtree` if emulating Windows under POSIX
27+
(see [#979](../../issues/979))
2628

2729
### Enhancements
2830
* added support for `O_NOFOLLOW` and `O_DIRECTORY` flags in `os.open`

pyfakefs/fake_filesystem_unittest.py

+4
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,10 @@ def setUp(self, doctester: Any = None) -> None:
919919
if self.has_fcopy_file:
920920
shutil._HAS_FCOPYFILE = False # type: ignore[attr-defined]
921921

922+
# do not use the fd functions, as they may not be available in the target OS
923+
if hasattr(shutil, "_use_fd_functions"):
924+
shutil._use_fd_functions = False # type: ignore[module-attr]
925+
922926
with warnings.catch_warnings():
923927
# ignore warnings, see #542 and #614
924928
warnings.filterwarnings("ignore")

pyfakefs/tests/fake_filesystem_shutil_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ def error_handler(_, path, _error_info):
192192
self.assertFalse(NonLocal.errorHandled)
193193
self.assertEqual(NonLocal.errorPath, "")
194194

195+
def test_rmtree_in_windows(self):
196+
# regression test for #979
197+
self.check_windows_only()
198+
base_path = self.make_path("foo", "bar")
199+
self.os.makedirs(self.os.path.join(base_path, "res"))
200+
self.assertTrue(self.os.path.exists(base_path))
201+
shutil.rmtree(base_path)
202+
self.assertFalse(self.os.path.exists(base_path))
203+
195204
def test_copy(self):
196205
src_file = self.make_path("xyzzy")
197206
dst_file = self.make_path("xyzzy_copy")

0 commit comments

Comments
 (0)