Prevent MemoryFS.removedir(..., recursive=True) removing non-empty parent…

Prevent MemoryFS.removedir(..., recursive=True) removing non-empty parent directories, and fixed up corresponding unit test.
Fixes Issue 137
parent bb170217
......@@ -484,6 +484,9 @@ class MemoryFS(FS):
if not dirname:
raise RemoveRootError(path)
del parent_dir.contents[dirname]
# stop recursing if the directory has other contents
if parent_dir.contents:
break
else:
pathname, dirname = pathsplit(path)
parent_dir = self._get_dir_entry(pathname)
......
......@@ -419,6 +419,7 @@ class FSTestCases(object):
self.fs.removedir("foo/bar/baz", recursive=True)
self.assert_(not check("foo/bar/baz"))
self.assert_(not check("foo/bar"))
self.assert_(check("foo/file.txt"))
# Ensure that force=True works as expected
self.fs.makedir("frollic/waggle", recursive=True)
self.fs.setcontents("frollic/waddle.txt",b("waddlewaddlewaddle"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment