
    si'                    :   S r SSKJr  SSK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JrJrJrJrJrJr  SSKJr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"J#r#  SSK$J%r%  \(       d  SSKJ&r&  \" \'5      r(S r)S r*S r+SSS jjr,S r-\ 4S jr.S r/g)z6Disk utility functions for deleting files and folders.    )annotationsN)	getLogger)	abspathbasenamedirnameexistsisdirisfilejoinnormpathsplit)STDOUTCalledProcessErrorcheck_output   )CONDA_TEMP_EXTENSION)context)on_win)TRACE   )	MAX_TRIES)islinklexists)make_writable)whichc           
        [        U 5      n [        (       a   [        SU  S3S[        S9nO [        R(                  " S5        [+        S5      (       a`  [-        S5      nU(       a8   [        USSS[/        [        R0                  " 5       S5      S -   U S -   /[        S!9n[2        R4                  " S5        [2        R4                  " U 5        g !    S nSSKJn  SSKJn  U" SS	S
S9 nUR                  SU" U 5       S35        UR                  S5        UR                  SU" U 5       S35        UR                  S5        UR                  nS S S 5        O! , (       d  f       O= f[        U5       nUR                  5       nX;  a  [        SU  SU 35      e S S S 5        O! , (       d  f       O= f[        R                  " S5      nSn	[        USSU/S
S S S U	S9n GN)! [         aP  n
U
R                   S:w  a  ["        R%                  SW SW 35        e ["        R'                  SW 35         S n
A
 GN~S n
A
ff = f= f!    GN= f! [         a    ["        R'                  SW 35         GNf = f)"Nz
RD /S /Q "z" > NUL 2> NULT)shellstderrr   )Utf8NamedTemporaryFile)quote_for_shellwz.batF)modesuffixdeletezRD /S 
zchcp 65001
zEXIT 0
zPath z not listed in file COMSPECi   z/dz/c)r   stdoutr   stdincreationflags   zRemoving folder z# the fast way failed.  Output was: z8removing dir contents the fast way failed.  Output was: z.emptyrsyncz-az--forcez--delete/r   )r   r   r   r   auxlib.compatr   utilsr    writenameopenreadRuntimeErrorosgetenvr   
returncodelogerrordebugmakedirsr	   r   r   getcwdshutilrmtree)pathoutr1   r   r    
batch_filecontentscontentcomspecCREATE_NO_WINDOWer+   s               :lib/python3.13/site-packages/conda/gateways/disk/delete.pyr>   r>   (   s^   D>Dv9	 TF.1fCb	KK! ??'NE&! %& h7#= 3J  &
C  MM(#
MM$Y,	+C4+VE$$vod.C-DB%GH$$^4$$vod.C-DB%GH$$Z0%??D   $Z8&mmoG**U4&8LTF+STT +  ZZ ))I.#-  #dD$/"2 & 	<<1$II*4&0STWSXY IIRSVRWX 		* * IIRSVRWXs~   C
 H< &7I 
H9G#A%E	G
E	G-'F	G
F,	(1G
H6&AH1*H91H66H9<I"I*)I*c                    [        U 5        [        R                  " U 5        g! [         Ga=     [        R                  " X S-   5         g! [         Ga    [
        (       a  [        [        R                  S5      n[        US5      n[        U5      (       a  [        U 5      u  p4U S-   nSn[        U5      (       a,  UR                  S   SU 3-   nUS-  n[        U5      (       a  M,  Sn [        SS	UUU[        U5      /[        S
9nOC! [          a    ["        R%                  SU  SU 35         Of = f["        R%                  U S35        ["        R'                  SU  S35          gf = ff = f)zIf files are in use, especially on windows, we can't remove them.
The fallback path is to rename them (but keep their folder the same),
which maintains the file handle validity.  See comments at:
https://serverfault.com/a/503769
z.conda_trashcondabinzrename_tmp.batr   r   z.conda_trash_z	< empty >zcmd.exez/Cr-   zrenaming file path z to trash failed.  Output was: zv is missing.  Conda was not installed correctly or has been corrupted.  Please file an issue on the conda github repo.zCould not remove or rename zQ.  Please remove this file manually (you may need to reboot to free file handles)N)r   r5   unlinkOSErrorrenamer   r   r   conda_prefixr   r   r
   splitextr   r   r   r   r8   r:   warning)r?   condabin_dirtrash_script_dirname_fndest_fncounterr@   s           rG   unlink_or_rename_to_trashrV      sx   -d
		$ *)	IId>12 '	v  $G$8$8*E#L2BC,''$)$KMH"^3GG //")"2"21"5-y8Q"Q1 !// &C* ) $ , ( # ( 1 $*
 . 		1$7VWZV[\ II'. )U U KK-dV 4; ;I'	*sQ   !$ E,ABE('E(*DE(%D0-E(/D004E($E,'E((E,c                :   [        U 5      n[        U5      (       a  [        [        R                  " U5      S 5      (       dZ  [        R
                  " U5        [        U5      n[        U5      (       a(  [        [        R                  " U5      S 5      (       d  MX  g g g g )N)r   r	   nextr5   scandirrmdir)r?   parent_paths     rG   remove_empty_parent_pathsr\      sl    $-K


T"**[*A4%H%H
k* 

T"**[*A4%H%H
%H
    c                   [        U 5      n [        R                  [        SU 5        [        U 5      (       a  [	        U 5      (       d  [        U 5        O7[        U 5      (       a  [        U 5        O[        R                  [        SU 5        [        U 5      (       a  [	        U 5      (       d  [        U 5        U(       a  [        U 5        [        U 5      (       a  [        R                  SU 5        gg)z
Completely delete path
max_retries is the number of times to retry on failure. The default is 5. This only applies
to deleting a directory.
If removing path fails and trash is True, files will be moved to the trash directory.
zrm_rf %sz0rm_rf failed. Not a link, file, or directory: %szrm_rf failed for %sFT)r   r8   r   r	   r   backoff_rmdirr   rV   delete_trashr\   info)r?   clean_empty_parentss     rG   rm_rfrc      s     4=DGGE:t$ T{{6$<<d	!$'I4P T{{6$<<T!$'t}}&-r]   c           	        U (       d  [         R                  n SS1n[        R                  " U SS9 H  u  p#nU Vs/ s H  oUU;  d  M
  UPM     snUS S & U Hq  n[        R                  " US5      (       d%  [        R                  " US[
        -   5      (       d  MD  [        X&5      n [        R                  " U5        [        U5        Ms     M     g s  snf ! [         a,  n[        R                  SXR                  U5         S nAM  S nAff = f)NenvspkgsTtopdown*.conda_trash**z%r errno %d
Cannot unlink %s.)sysprefixr5   walkfnmatchr   r   rJ   r\   rK   r8   r:   errno)	rl   excluderootdirsfilesdfnfilenamerF   s	            rG   r`   r`      s    vGWWVT:E"7dw&61d7QBr#344C..9 9  >VIIh'-h7  ;7  VII>77HUUVs#   	CC&!C
D!DDc                    [        U 5      (       d  g  [        U 5        [        R                  " U SS9 H#  u  p#nU H  n[	        [        X%5      5        M     M%     g !    NA= f)NFrg   )r	   r>   r5   rm   rV   r   )dirpath	max_triesrq   rr   rs   files         rG   r_   r_      sY    >>w  WWWe<ED%d4&67  = 	s   A Ac                   [        U 5      (       + nU(       dm  [        R                  " U 5       HS  u  p#nU HG  n[        R                  " US5      (       a  M!  [        R                  " US[        -   5      (       a  MF      g   MU     g)zSometimes we can't completely remove a path because files are considered in use
by python (hardlinking confusion).  For our tests, it is sufficient that either the
folder doesn't exist, or nothing but temporary file copies are left.
ri   rj   FT)r   r5   rm   rn   r   )r?   cleanrq   rr   fnsru   s         rG   path_is_cleanr~     sd    
 tE!wwt}ODOOB(899r31E+EFF    - r]   )F)r?   zstr | os.PathLikerb   boolreturnr   )0__doc__
__future__r   rn   r5   r=   rk   loggingr   os.pathr   r   r   r   r	   r
   r   r   r   
subprocessr   r   r   base.constantsr   base.contextr   common.compatr   common.constantsr    r   linkr   r   permissionsr   r   __name__r8   r>   rV   r\   rc   r`   r_   r~    r]   rG   <module>r      s    = "  	  
 
 
 
 @ ? 2 # # %  ! & ]@3l+<V$ &/ 8 r]   