o
    ˜¨Êh  ã                   @   sJ   d Z ddlZddlZddl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)Úcopystat)ÚlocksÚfile_move_safec                 C   sZ   t tjdƒrztj | |¡W S  ty   Y dS w tj tj | ¡¡tj tj |¡¡kS )NÚsamefileF)ÚhasattrÚosÚpathr   ÚOSErrorÚnormcaseÚabspath)ÚsrcÚdst© r   úH/var/www/html/env/lib/python3.10/site-packages/django/core/files/move.pyÚ	_samefile   s   ÿ
ÿr   é   Fc              
   C   sž  t | |ƒrdS z|st |tj¡rtd| ƒ‚t | |¡ W dS  ty(   Y nw t| dƒ�S}t |tjtj	B t
tddƒB |sBtjndB ¡}z(t |tj¡ d}|dkrc| |¡}t ||¡ |dksTW t |¡ t |¡ nt |¡ t |¡ w W d  ƒ n1 s„w   Y  zt| |ƒ W n ty© } z|jtjkrŸ‚ W Y d}~nd}~ww zt | ¡ W dS  tyÎ } zt
|ddƒdkrÃ‚ W Y d}~dS d}~ww )	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      sl   
ÿÿýÿ
þýý	
þ€

ÿíÿ€üÿ€û)r   F)
Ú__doc__r'   r   Úshutilr   Údjango.core.filesr   Ú__all__r   r   r   r   r   r   Ú<module>   s    ÿ