σ
έ²k^c           @` sπ  d  d l  m Z m Z m Z m Z d  d l m Z d  d l Z d  d l m	 Z	 d  d l
 m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l Z d  d l m Z m  Z  m! Z! d  d l" Z" d d	 l# m$ Z$ m% Z% d d
 l& m' Z' m( Z( d d l) m* Z* m+ Z+ d d l, m- Z- d d l. m/ Z/ d d l0 m1 Z1 e1 sd d l2 m3 Z3 n  e	 e4  Z5 d   Z6 d   Z7 d   Z8 d e9 e: d  Z; e; Z< Z= Z> d   Z? e$ d  Z@ d   ZA d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   ENOENTN(   t	   getLogger(   t   environt   getcwdt   listdirt   makedirst   renamet   rmdirt   unlinkt   walk(	   t   abspatht   basenamet   dirnamet   existst   isdirt   isfilet   joint   normpatht   split(   t   CalledProcessErrort   STDOUTt   check_outputi   (   t	   MAX_TRIESt   exp_backoff_fn(   t   islinkt   lexists(   t   make_writablet   recursive_make_writablei   (   t   CONDA_TEMP_EXTENSION(   t   context(   t   on_win(   t   whichc         O` s  t  |   }  t rΖy% t d j |   d t d t } Wqry+d  } d d l m } d d l	 m
 } | d d d	 d
 d t  h } | j d j | |  g    | j d  | j d j | |  g    | j d  | j } Wd  QXt | d  % } | j   }	 |  |	 k st  Wd  QXt d }
 d } t |
 d d | g d t d d  d d  d d  d | } WqΓt k
 rΎ} | j d k r₯t j d j |     qΏt j d j |   qΓXqrXn¬ y t d  Wn n Xt d  } | rrt d  rry< t | d d d t t   d  d |  d g d t } Wn' t k
 rat j d j |   n Xt j d  n  t j |   d  S(    Nu   RD /S /Q "{}" > NUL 2> NULt   shellt   stderri    (   t   Utf8NamedTemporaryFile(   t   quote_for_shellt   modeu   wt   suffixu   .batt   deleteu	   RD /S {}
u   chcp 65001
u   EXIT 0
u   ru   COMSPECi   u   /du   /ct   stdoutt   stdint   creationflagsi   u7   Removing folder {} the fast way failed.  Output was: {}u:   removing dir contents the fast way failed.  Output was: {}u   .emptyu   rsyncu   -au   --forceu   --deleteu   /(   R   R"   R   t   formatt   TrueR   t   Nonet   conda._vendor.auxlib.compatR&   t   conda.utilsR'   t   Falset   writet   namet   opent   readt   AssertionErrorR   R   t
   returncodet   logt   errort   debugR	   R#   R   R   R   t   shutilt   rmtree(   t   patht   argst   kwargst   outR5   R&   R'   t
   batch_filet   contentst   contentt   comspect   CREATE_NO_WINDOWt   et   rsync(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyR>      s\    


c         C` sx  y t  |   t |   WnYt k
 rsy t |  |  d  Wqtt k
 rot rVt t j d  } t | d  } t |  r=t	 |   \ } } |  d } d } x4 t
 |  rΨ | j d d j |  } | d 7} q₯ Wd } y. t d d	 | | | t |  g d
 t } WqSt k
 r9t j d j |  |   qSXqVt j d j |   n  t j d j |    qtXn Xd S(   uυ   If 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
    u   .conda_trashu   condabinu   rename_tmp.bati   i    u   .conda_trash_{}u	   < empty >u   cmd.exeu   /CR%   u6   renaming file path {} to trash failed.  Output was: {}ux   {} is missing.  Conda was not installed correctly or has been corrupted.  Please file an issue on the conda github repo.un   Could not remove or rename {}.  Please remove this file manually (you may need to reboot to free file handles)N(   R   R   t   EnvironmentErrorR
   R"   R   R!   t   conda_prefixR   R   R   t   splitextR.   R   R   R   R   R:   R<   t   warn(   R?   t   condabin_dirt   trash_scriptt   _dirnamet   _fnt   dest_fnt   counterRB   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   unlink_or_rename_to_trashe   s:    

c         C` sF   t  |   } x3 t |  rA t |  rA t |  t  |  } q Wd  S(   N(   R   R   R   R   (   R?   t   parent_path(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   remove_empty_parent_paths   s    
i   c         O` sΓ   zo t  |   }  t j d |   t |   rE t |   rE t |   n) t |   r^ t |   n t j d |   Wd t |   r t j d |   t	 SXt |   r¬ t
 |   n  | rΏ t |   n  t S(   uχ   
    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.
    u   rm_rf %su0   rm_rf failed. Not a link, file, or directory: %sNu   rm_rf failed for %s(   R   R:   t   traceR   R   t   backoff_rmdirR   RT   t   infoR3   t   delete_trashRV   R/   (   R?   t   max_retriest   trasht   clean_empty_parentsR@   t   kw(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   rm_rf   s     c   	      C` s  |  s t  j }  n  t d d g  } xα t |  d t D]Ν \ } } } g  | D] } | | k rM | ^ qM | (x | D] } t j | d  s‘ t j | d t  rs t | |  } y t |  t	 |  Wq t
 t f k
 rό } t j d | | j |  q Xqs qs Wq7 Wd  S(   Nu   envsu   pkgst   topdownu   *.conda_trash*u   *u   %r errno %d
Cannot unlink %s.(   t   syst   prefixt   setR   R/   t   fnmatchR    R   R   RV   t   OSErrort   IOErrorR:   R<   t   errno(	   Rb   t   excludet   roott   dirst   filest   dt   fnt   filenameRH   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyRZ   Ά   s    "&
c         ` s   t  |   s d  S  f d       f d   } y t |   Wn n XxG t |  d t D]3 \ } } } x! | D] } t t | |   qr Wq\ Wd  S(   Nc         ` sD   t  | d d d   t k r  d  St t |  d   |  |  d  S(   Ni   u   errnot	   max_tries(   t   getattrR0   R   R   R   (   t   funcR?   t   exc_info(   Ro   (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   retryΛ   s    c         ` sl   y' t  |   t t |  d  d   Wn> t t f k
 rg } | j t k ra t j d |   qh   n Xd  S(   Nt   onerrorRo   u   no such file or directory: %s(	   R   R   R>   Rf   Re   Rg   R   R:   RW   (   R?   RH   (   Ro   Rs   (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   _rmdirΡ   s    
R`   (   R   R>   R   R3   RT   R   (   t   dirpathRo   Ru   Ri   Rj   Rk   t   file(    (   Ro   Rs   s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyRX   Η   s    	"c         C` sw   t  |   } | ss x] t |   D]L \ } } } x: | D]2 } t j | d  pa t j | d t  s6 t Sq6 Wq  Wn  t S(   uπ   Sometimes 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.u   *.conda_trash*u   *(   R   R   Rd   R    R3   R/   (   R?   t   cleanRi   Rj   t   fnsRm   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   path_is_cleanζ   s    (B   t
   __future__R    R   R   R   Rg   R   Rd   t   loggingR   t   osR   R   R   R	   R
   R   R   R   t   os.pathR   R   R   R   R   R   R   R   R   R=   t
   subprocessR   R   R   Ra   t    R   R   t   linkR   R   t   permissionsR   R   t   base.constantsR    t   base.contextR!   t   common.compatR"   t   common.pathR#   t   __name__R:   R>   RT   RV   R/   R3   R_   t   try_rmdir_all_emptyt   move_to_trasht   move_path_to_trashRZ   RX   Rz   (    (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/delete.pyt   <module>   s2   ":@	H	*		