diff --git a/django/core/files/move.py b/django/core/files/move.py index 95d69f9d94..b25a1c8b2d 100644 --- a/django/core/files/move.py +++ b/django/core/files/move.py @@ -13,20 +13,6 @@ from django.core.files import locks __all__ = ["file_move_safe"] -def _samefile(src, dst): - # Macintosh, Unix. - if hasattr(os.path, "samefile"): - try: - return os.path.samefile(src, dst) - except OSError: - return False - - # All other platforms: check for same pathname. - return os.path.normcase(os.path.abspath(src)) == os.path.normcase( - os.path.abspath(dst) - ) - - def file_move_safe( old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False ): @@ -40,8 +26,11 @@ def file_move_safe( ``FileExistsError``. """ # There's no reason to move if we don't have to. - if _samefile(old_file_name, new_file_name): - return + try: + if os.path.samefile(old_file_name, new_file_name): + return + except OSError: + pass try: if not allow_overwrite and os.access(new_file_name, os.F_OK):