a
    5Xh                     @   sD   d Z ddlZddlmZmZ ddlmZ dgZdd Zdd
dZ	dS )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 tjdr2ztj| |W S  ty0   Y dS 0 tjtj| tjtj|kS )NsamefileF)hasattrospathr   OSErrornormcaseabspath)srcdst r   [/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/django/core/files/move.py	_samefile   s    
r      Fc                 C   s  t | |rdS z0|s.t|tjr.td| t| | W dS  tyP   Y n0 t| d}t|tjtj	B t
tddB |stjndB }zJt|tj d}|dkr||}t|| qW t| t| nt| t| 0 W d   n1 s0    Y  zt| | W n8 tyT   zt| | W n tyN   Y n0 Y n0 zt|  W n: ty } z t
|dddkr W Y d}~n
d}~0 0 dS )	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   lockZLOCK_EXreadwriteZunlockcloser   PermissionErrorr   remove)Zold_file_nameZnew_file_name
chunk_sizeZallow_overwriteZold_filefdZcurrent_chunker   r   r   r      s\    

	


,)r   F)
__doc__r   shutilr   r   Zdjango.core.filesr   __all__r   r   r   r   r   r   <module>   s    