Skip to content

Normalize file path in RemoveObject() #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The release versions are PyPi releases.
* Added the CHANGES.md release notes to the release manifest

#### Fixes
* `FakeShutilModule.rmtree` failed for directory ending with path separator (#177)
* Case incorrectly handled for added Windows drives
* `pathlib.glob()` incorrectly handled case under MacOS (#167)
* tox support was broken (#163)
Expand Down
10 changes: 10 additions & 0 deletions fake_filesystem_shutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def testRmtree(self):
self.assertFalse(self.filesystem.Exists('%s/subdir' % directory))
self.assertFalse(self.filesystem.Exists('%s/subfile' % directory))

def testRmtreeWithTrailingSlash(self):
directory = 'xyzzy'
self.filesystem.CreateDirectory(directory)
self.filesystem.CreateDirectory('%s/subdir' % directory)
self.filesystem.CreateFile('%s/subfile' % directory)
self.shutil.rmtree(directory + '/')
self.assertFalse(self.filesystem.Exists(directory))
self.assertFalse(self.filesystem.Exists('%s/subdir' % directory))
self.assertFalse(self.filesystem.Exists('%s/subfile' % directory))

def testRmtreeWithoutPermissionForAFile(self):
self.filesystem.CreateFile('/foo/bar')
self.filesystem.CreateFile('/foo/baz', st_mode=stat.S_IFREG | 0o444)
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ def RemoveObject(self, file_path):
of the path refers to something other than a directory.
OSError: if the directory is in use (eg, if it is '/').
"""
file_path = self.NormalizeCase(file_path)
file_path = self.NormalizePath(self.NormalizeCase(file_path))
if self._IsRootPath(file_path):
raise OSError(errno.EBUSY, 'Fake device or resource busy',
file_path)
Expand Down