1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #35320 -- Removed unnecessary django.core.files.move._samefile() hook.

os.path.samefile() uses the same implementation on Windows as all other
platforms since Python 3.4.
This commit is contained in:
Ben Cail 2024-03-20 16:46:28 -04:00 committed by Mariusz Felisiak
parent 6a37e9bfae
commit 8dbfef4695

View File

@ -13,20 +13,6 @@ from django.core.files import locks
__all__ = ["file_move_safe"] __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( def file_move_safe(
old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False old_file_name, new_file_name, chunk_size=1024 * 64, allow_overwrite=False
): ):
@ -40,8 +26,11 @@ def file_move_safe(
``FileExistsError``. ``FileExistsError``.
""" """
# There's no reason to move if we don't have to. # There's no reason to move if we don't have to.
if _samefile(old_file_name, new_file_name): try:
return if os.path.samefile(old_file_name, new_file_name):
return
except OSError:
pass
try: try:
if not allow_overwrite and os.access(new_file_name, os.F_OK): if not allow_overwrite and os.access(new_file_name, os.F_OK):