Skip to content

Commit

Permalink
Added handling for rename symlink with trailing sep to self
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed May 18, 2018
1 parent a53706e commit 240c8dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,10 @@ def _handle_posix_dir_link_errors(self, new_file_path, old_file_path,
return
error = errno.ENOTDIR if ends_with_sep else errno.EISDIR
self.raise_os_error(error, new_file_path)
if (ends_with_sep and self.islink(old_file_path) and
old_file_path == new_file_path and not self.is_windows_fs):
self.raise_os_error(errno.ENOTDIR, new_file_path)


def _rename_to_existing_path(self, force_replace, new_file_path,
old_file_path, old_object, ends_with_sep):
Expand Down
19 changes: 17 additions & 2 deletions pyfakefs/tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def test_circular_readlink_with_trailing_separator_macos(self):
self.check_macos_only()
file_path = self.make_path('foo')
self.os.symlink(file_path, file_path)
print(self.os.readlink(file_path + self.os.sep))
self.os.readlink(file_path + self.os.sep)

def test_circular_readlink_with_trailing_separator_windows(self):
# Regression test for #372
Expand Down Expand Up @@ -2256,7 +2256,22 @@ def test_lexists_broken_link_with_trailing_sep(self):
link_path = self.create_broken_link_path_with_trailing_sep()
self.assertFalse(self.os.path.lexists(link_path))

# hard link related tests
def test_rename_link_with_trailing_sep_to_self_windows(self):
self.check_windows_only()
self.skip_if_symlink_not_supported()
path = self.make_path('foo')
self.os.symlink(self.base_path, path)
self.os.rename(path + self.os.sep, path) # no error

def test_rename_link_with_trailing_sep_to_self_posix(self):
# Regression test for #395
self.check_posix_only()
path = self.make_path('foo')
self.os.symlink(self.base_path, path)
self.assert_raises_os_error(
errno.ENOTDIR, self.os.rename, path + self.os.sep, path)

# hard link related tests
def test_link_bogus(self):
# trying to create a link from a non-existent file should fail
self.skip_if_symlink_not_supported()
Expand Down

0 comments on commit 240c8dd

Please sign in to comment.