File: //usr/lib/python3/dist-packages/django/core/files/__pycache__/move.cpython-310.pyc
o
�a� � @ sH d Z ddlZddlZddlmZ ddlmZ dgZdd� Zdd
d�Z dS )z�
Move a file in the safest way possible::
>>> from django.core.files.move import file_move_safe
>>> file_move_safe("/tmp/old_file", "/tmp/new_file")
� N)�copystat)�locks�file_move_safec C sZ t tjd�rztj�| |�W S ty Y dS w tj�tj�| ��tj�tj�|��kS )N�samefileF)�hasattr�os�pathr �OSError�normcase�abspath)�src�dst� r �8/usr/lib/python3/dist-packages/django/core/files/move.py� _samefile s ��r � Fc
C s� t | |�rdS z|st�|tj�rtd| ��t�| |� W dS ty( Y nw t| d��S}t�|tjtj B t
tdd�B |sBtjndB �}z(t�
|tj� d}|dkrc|�|�}t�||� |dksTW t�|� t�|� nt�|� t�|� w W d � n1 s�w Y zt| |� W n ty� } z
|jtjkr�� W Y d}~nd}~ww zt�| � W dS ty� } zt
|dd�dkr W Y d}~dS d}~ww ) aU
Move a file from one location to another in the safest way possible.
First, try ``os.rename``, which is simple but will break across filesystems.
If that fails, stream manually from one file to another in pure Python.
If the destination file exists and ``allow_overwrite`` is ``False``, raise
``FileExistsError``.
Nz8Destination file %s exists and allow_overwrite is False.�rb�O_BINARYr � �winerror� )r r �access�F_OK�FileExistsError�renamer �open�O_WRONLY�O_CREAT�getattr�O_EXCLr �lock�LOCK_EX�read�write�unlock�closer �PermissionError�errno�EPERM�remove)�
old_file_name�
new_file_name�
chunk_size�allow_overwrite�old_file�fd�
current_chunk�er r r r sV
��
��
��������)r F)
�__doc__r'