
    si                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJrJrJrJrJrJr  SSKJr  SS	KJrJr  S
SKJr  S
SKJr  S
SKJr  S
SK J!r!  S
SK"J#r#  S
SK$J%r%  SSK&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-  \" \.5      r/\R`                  " S5      r1 " S S\25      r3S r4SS jr5\SSS jj5       r6SS jr7S S jr8g)!zCDisk utility functions for modifying existing files or directories.    )annotationsN)contextmanager)EINVALEPERMEXDEV)	getLogger)basenamedirnameexistsisdirjoinsplit)move)PIPEPopen   )DRY_RUN_PREFIX)context)on_win)TRACE)expand)NotWritableError   )exp_backoff_fnmkdir_pmkdir_p_sudo_safe)rm_rf)lexistss   ^(#!((?:\\ |[^ \n\r])+)(.*))c                      \ rS rSrSrg)CancelOperation     N)__name__
__module____qualname____firstlineno____static_attributes__r"       :lib/python3.13/site-packages/conda/gateways/disk/update.pyr    r        s    r(   r    c                   S n [        [        U S5      n[        R                  [        SU 5        UR	                  5       nUR                  S5         UR                  U" U5      5        UR                  5          U(       a  UR                  5         gg! [         a     Of = f U(       a  UR                  5         g! U(       a  UR                  5         f f = f)Nzrb+z"in-place update path locked for %sr   TF)
r   openlogr   readseekwritetruncatecloser    )file_full_pathcallbackfhdatas       r)   update_file_in_place_as_binaryr6   $   s     
BD.%8;^Lwwy

	HHXd^$KKM HHJ   		HHJ HHJ s*   AB< 'B 
B B< B  B< <Cc           	        [        U5      (       a  U(       a  [        U5        [        U 5      (       a3  [        R                  [        SX5         [        R
                  " X5        g [        R                  [        S	U 5        g ! [         Ga<  n[        (       a  [        U 5      [        U5      :X  a  [        R                  R                  U 5      (       a  [        [        R                  S5      n[        US5      n[        U5      (       aF  [        U 5      u  pg[!        U5      n[#        SSXVXx/[$        [$        S9n	U	R'                  5       u  p S nAg [        R)                  U S35         S nAg UR*                  [,        [.        [0        4;   a7  [        R                  [        SU UUR*                  5        [3        X5         S nAg e S nAff = f)
Nzrenaming %s => %scondabinzrename_tmp.batzcmd.exez/C)stdoutstderrzv is missing.  Conda was not installed correctly or has been corrupted.  Please file an issue on the conda github repo.zHCould not rename %s => %s due to errno [%s]. Falling back to copy/unlinkz.cannot rename; source path does not exist '%s')r   r   r,   r   osrenameOSErrorr   r
   pathisfiler   r   conda_prefixr   r   r	   r   r   communicatedebugerrnor   r   r   r   )source_pathdestination_pathforceecondabin_dirrename_script_dirname_src_fn_dest_fnpr9   r:   s               r)   r<   r<   :   sr     U{*KJ'	IIk4P 	GUO  %	K(G4D,EEGGNN;//#G$8$8*E $\3C D-(((-k(:%H'(89H"D-7U##A
 &']]_NFFII(/ *U U  VUE22 &$GG [33K%	s,   B G	B>GG-AGGG	c              #     #    Uc  [         R                  " 5       nU(       a  [        [         SU  SU 35        Sv   g [	        XSS9  Sv   g! [
         a  n[	        XSS9  UeSnAff = f7f)z
Used for removing a directory when there are dependent actions (i.e. you need to ensure
other actions succeed before removing it).

Example:
    with rename_context(directory):
        # Do dependent actions here
Nz rename_context z > T)rF   )tempfilemkdtempprintr   r<   	Exception)sourcedestinationdry_runexcs       r)   rename_contextrW   k   so      &&(  0K=IJv$/ {$/	s(   <A,A A,
A)A$$A))A,c                &    [        [        XU5        g )N)r   r<   )rD   rE   rF   s      r)   backoff_renamerY      s    6;%@r(   c                    [        U 5      n [        R                  [        SU 5        [        U 5      (       a  [        R
                  " U S 5        g[        U 5      n[        U5      (       d&  U(       a  U(       a  [        U5        O0[        U5        O$[        [        U 5      5      (       d  [        S5      e[        U S5          S S S 5        g! , (       d  f       g= f! [         a  n[        XR                  US9eS nAff = f)Nztouching path %sTzTarget path is not a directory.aF)	caused_by)r   r,   r   r   r;   utimer
   r   r   r   r=   r+   r   rC   )r>   mkdir	sudo_safedirpathrG   s        r)   touchra      s    ;d|)404==HHT4 dmG>>e%g.G$WT]++!"CDDdC !  !  ;tWW::;s=   AC A1C CC 
CC C 
D 'C;;D )F)NF)rS   strrT   z
str | NonerU   bool)FF)9__doc__
__future__r   r;   rerO   
contextlibr   rC   r   r   r   loggingr   os.pathr	   r
   r   r   r   r   shutilr   
subprocessr   r   base.constantsr   base.contextr   common.compatr   common.constantsr   common.pathr   
exceptionsr    r   r   r   deleter   linkr   r#   r,   compileSHEBANG_REGEXrR   r    r6   r<   rW   rY   ra   r"   r(   r)   <module>rw      s    J " 	 	  % & &  A A  " , # # % ! * 8 8  

;<	i 	,.Vb  4A#;r(   