B
    ©0H[Œ  ã               @   sH   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   sX   t tjdƒr0ytj | |¡S  tk
r.   dS X tj tj | ¡¡tj tj |¡¡kS )NÚsamefileF)ÚhasattrÚosÚpathr   ÚOSErrorÚnormcaseÚabspath)ÚsrcÚdst© r   úZC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\core\files\move.pyÚ	_samefile   s    r   é   Fc          
   C   sx  t | |ƒrdS y.|s.t |tj¡r.td| ƒ‚t | |¡ dS  tk
rP   Y nX t| dƒ�†}t |tjtj	B t
tddƒB |s„tjndB ¡}z:t |tj¡ d}x"|dkrÂ| |¡}t ||¡ q¢W W dt |¡ t |¡ X W dQ R X yt| |ƒ W n4 tk
�r* } z|jtjk�r‚ W dd}~X Y nX yt | ¡ W n8 tk
�rr } zt
|ddƒdk�rb‚ W dd}~X Y nX dS )	aM  
    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
    ``IOError``.
    Nz7Destination file %s exists and allow_overwrite is FalseÚrbÚO_BINARYr   ó    Úwinerroré    )r   r   ÚaccessÚF_OKÚIOErrorÚrenamer	   ÚopenÚO_WRONLYÚO_CREATÚgetattrÚO_EXCLr   ÚlockZLOCK_EXÚreadÚwriteZunlockÚcloser   ÚPermissionErrorÚerrnoZEPERMÚ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%   r   Úshutilr   Zdjango.core.filesr   Ú__all__r   r   r   r   r   r   Ú<module>   s   