@@ -408,6 +408,9 @@ def _check_copy(self, src_path, dst_path, overwrite=False):
408408 # check src_path exists and is a file
409409 if self .gettype (src_path ) is not ResourceType .file :
410410 raise errors .FileExpected (src_path )
411+ # it's not allowed to copy a file onto itself
412+ if _src_path == _dst_path :
413+ raise errors .IllegalDestination (dst_path )
411414 # check dst_path does not exist if we are not overwriting
412415 if not overwrite and self .exists (_dst_path ):
413416 raise errors .DestinationExists (dst_path )
@@ -440,9 +443,6 @@ def copy(self, src_path, dst_path, overwrite=False, preserve_time=False):
440443 self .getsyspath (_src_path ),
441444 self .getsyspath (_dst_path ),
442445 )
443- # exit early if we copy the file onto itself
444- if overwrite and _src_sys == _dst_sys :
445- return
446446 # attempt using sendfile
447447 try :
448448 # initialise variables to pass to sendfile
@@ -474,9 +474,6 @@ def copy(self, src_path, dst_path, overwrite=False, preserve_time=False):
474474 self .getsyspath (_src_path ),
475475 self .getsyspath (_dst_path ),
476476 )
477- # exit early if we copy the file onto itself
478- if overwrite and _src_sys == _dst_sys :
479- return
480477 shutil .copy2 (_src_sys , _dst_sys )
481478
482479 # --- Backport of os.scandir for Python < 3.5 ------------
0 commit comments