File: //usr/local/CyberCP/lib/python3.10/site-packages/django/core/files/__pycache__/move.cpython-310.pyc
o
�h� � @ sF d Z ddlZddlmZmZ ddlmZ dgZdd� Z dd
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)�copymode�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 �I/usr/local/CyberCP/lib/python3.10/site-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� zt| |� W n ty� Y nw Y nw 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 �PermissionErrorr �remove)�
old_file_name�
new_file_name�
chunk_size�allow_overwrite�old_file�fd�
current_chunk�er r r r sp
����
���
��
�����
���)r F)
�__doc__r �shutilr r �django.core.filesr �__all__r r r r r r �<module> s �