
    Hwg                     B    d Z ddlZddlmZmZ ddlmZ dgZd Z	 ddZ	y)	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                    t        t        j                  d      r!	 t        j                  j                  | |      S t        j                  j                  t        j                  j                  |             t        j                  j                  t        j                  j                  |            k(  S # t        $ r Y yw xY w)NsamefileF)hasattrospathr   OSErrornormcaseabspath)srcdsts     M/var/www/horilla/myenv/lib/python3.12/site-packages/django/core/files/move.py	_samefiler      s    rww
#	77##C--
 77BGGOOC01RWW5E5E
6  	  		s   B5 5	C Cc           
      &   t        | |      ry	 |s2t        j                  |t        j                        rt	        d|z        t        j
                  | |       y# t        $ r Y nw xY wt        | d      5 }t        j                  |t        j                  t        j                  z  t        t        dd      z  |st        j                  ndz        }	 t        j                  |t        j                         d}|dk7  r-|j                  |      }t        j                   ||       |dk7  r-t        j"                  |       t        j$                  |       n/# t        j"                  |       t        j$                  |       w xY w	 ddd       n# 1 sw Y   nxY w	 t'        | |       n,# t(        $ r  	 t+        | |       n# t(        $ r Y nw xY wY nw xY w	 t        j,                  |        y# t(        $ r}t        |dd      dk7  r Y d}~yd}~ww xY 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   PermissionErrorr   remove)old_file_namenew_file_name
chunk_sizeallow_overwriteold_filefdcurrent_chunkes           r   r   r      s    .299]BGG#D!J  
 			-/  	 
mT	" hWW**"j!,- %4299<
	JJr5==) M3& (j 9]+  3& LLHHRL LLHHRLL'  *
. 
	]M2 		
		-  
 1j!$* +s   A
A 	A&%A&5AFAE++F,FFFF) )	G3G ?G 	G	GGGGG, ,	H5HH)i   F)
__doc__r
   shutilr   r   django.core.filesr   __all__r   r    r   r   <module>r7      s/    
 % #
 INHr   