Skip to content

Commit 5b4941a

Browse files
committed
Simplify patch.
1 parent 12aaf67 commit 5b4941a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Lib/pathlib/_abc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ def is_symlink(self):
469469
except (OSError, ValueError):
470470
return False
471471

472+
def _ensure_different_file(self, other_path):
473+
"""
474+
Raise OSError(EINVAL) if both paths refer to the same file.
475+
"""
476+
pass
477+
472478
def _ensure_distinct_path(self, other_path):
473479
"""
474480
Raise OSError(EINVAL) if the other path is within this path.
@@ -692,6 +698,7 @@ def _copy_file(self, target):
692698
"""
693699
Copy the contents of this file to the given target.
694700
"""
701+
self._ensure_different_file(target)
695702
with self.open('rb') as source_f:
696703
try:
697704
with target.open('wb') as target_f:

Lib/pathlib/_local.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ def is_socket(self):
633633
except (OSError, ValueError):
634634
return False
635635

636-
637636
def samefile(self, other_path):
638637
"""Return whether other_path is the same or not as this file
639638
(as returned by os.path.samefile()).
@@ -873,21 +872,19 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=False):
873872
_read_metadata = read_file_metadata
874873
_write_metadata = write_file_metadata
875874

876-
def _copy_file(self, target):
877-
"""
878-
Copy the contents of this file to the given target.
879-
"""
880-
if copyfile:
875+
if copyfile:
876+
def _copy_file(self, target):
877+
"""
878+
Copy the contents of this file to the given target.
879+
"""
881880
try:
882881
target = os.fspath(target)
883882
except TypeError:
884883
if not isinstance(target, PathBase):
885884
raise
885+
PathBase._copy_file(self, target)
886886
else:
887887
copyfile(os.fspath(self), target)
888-
return
889-
self._ensure_different_file(target)
890-
PathBase._copy_file(self, target)
891888

892889
def chmod(self, mode, *, follow_symlinks=True):
893890
"""

0 commit comments

Comments
 (0)