Skip to content

Commit

Permalink
Fixed #35320 -- Removed unnecessary django.core.files.move._samefile(…
Browse files Browse the repository at this point in the history
…) hook.

os.path.samefile() uses the same implementation on Windows as all other
platforms since Python 3.4.
  • Loading branch information
bcail authored and felixxm committed Mar 21, 2024
1 parent 6a37e9b commit 8dbfef4
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions django/core/files/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@
__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
):
Expand All @@ -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):
Expand Down

0 comments on commit 8dbfef4

Please sign in to comment.