
ݲk^c           @` s[  d  d l  m Z m Z m Z m Z d  d l m Z d  d l m Z	 m
 Z
 d  d l m Z m Z m Z m Z d d l m Z m Z d d l m Z m Z d< Z e e  Z e r d   Z n7 y d  d l m Z e Z Wn e k
 r d   Z n Xe sd  d l m Z m Z e Z e Z n d  d l  m! Z! m" Z" e! j# j$ Z% e" j& e% _' e" j( e" j( e" j) g e% _* y7 e! j# j+ Z, e" j& e, _' e" j( e" j( e" j- g e, _* Wn e. k
 rd Z, n Xd   Z0 d   Z1 e0 Z e1 Z e oe sd  d l m2 Z2 e Z e Z e2 Z2 n3d  d l  m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m! Z! m" Z" d  d l8 Z8 d  d l m9 Z9 d  d l m: Z: d  d l; Z; d d l< m= Z= e= j> j? Z? d   Z d   Z d Z@ d ZA d  ZB d! ZC d  ZD d" ZE d# e4 f d$     YZF e3 eF  ZG e! j# jH ZI e" jJ eG f eI _* e" jK eI _' e! j# jL ZM e" jK eG f eM _* e" jN eM _' e" jK d%  jO ZP e! j# jQ ZR e" j- eR _' e" jJ f eR _* d&   ZS d'   ZT d( e? jU f d)     YZU d*   ZV d+   ZW d,   ZX d-   ZY d.   ZZ d/   Z[ d Z\ d0 Z] d1 Z^ d2 Z_ e3 e" j-  Z` e" j) Za d3 e4 f d4     YZb e3 eb  Zc e! j# jd Ze e" jJ e" j- e" j- ec e" j- e" j- e" jK f ee _* e" jK ee _' e! j# jf Zf e" jK f ef _* e" jN ef _' d  d5 l  mg Zg mh Zh mi Zi mj Zj mk Zk ml Zl d6 e4 f d7     YZm d8   Z2 e! j# jn Zn e" jK e" j- e" j) e" j- e" j) e" j- e` ea g en _* e" j& en _' d d9  Zo d: ep f d;     YZq eq   Zr d S(=   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t	   getLogger(   t   chmodt   lstat(   t   abspatht   isdirt   islinkt   lexistsi   (   t   PY2t   on_win(   t   CondaOSErrort
   ParseErroru   islinku   lchmodu   lexistsu   linku   readlinku
   stat_nlinku   symlinkc         C` sT   y t  |  | d t Wn6 t t t f k
 rO t |   sP t  |  |  qP n Xd  S(   Nt   follow_symlinks(   t   os_chmodt   Falset	   TypeErrort   NotImplementedErrort   SystemErrorR	   (   t   patht   mode(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   lchmod   s
    (   R   c         C` s    t  |   s t |  |  n  d  S(   N(   R	   R   (   R   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR   #   s    (   t   linkt   symlink(   t   windllt   wintypesc         C` s/   t  | |  d  s+ t d |  | f   n  d S(   u;   Equivalent to os.link, using the win32 CreateHardLink call.u*   win32 hard link failed
  src: %s
  dst: %sN(   t   CreateHardLinkt   NoneR   (   t   srct   dst(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   win_hard_link=   s    c         C` sP   t  d k r t d   n  t  | |  t |    sL t d |  | f   n  d S(   uB   Equivalent to os.symlink, using the win32 CreateSymbolicLink call.u   win32 soft link not supportedu*   win32 soft link failed
  src: %s
  dst: %sN(   t   CreateSymbolicLinkR   R   R   (   R   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   win_soft_linkB   s    (   t   readlink(   t   POINTERt	   Structuret   byreft   c_uint64t   castR   R   N(   t   getcwd(   t   isfile(   t   sixc         C` s   t  |   o t |   S(   u(   Determine if the given path is a symlink(   t   is_reparse_pointt
   is_symlink(   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR	   ]   s    c         C` s4   t  |   r t St |   r  t St |   r0 t St S(   N(   R	   t   TrueR   R*   R   (   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR
   a   s    i  I      I    i   i   t   WIN32_FIND_DATAc        
   B` s   e  Z d  e j f d e j f d e j f d e j f d e j d f d e j d f d e j e f d e j d	 f g Z e d
    Z	 RS(   u   file_attributesu   creation_timeu   last_access_timeu   last_write_timeu   file_size_wordsi   u   reservedu   filenameu   alternate_filenamei   c         C` s   t  |  j t t   j S(   N(   R(   t   file_size_wordsR$   R'   t   contents(   t   self(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt	   file_size}   s    (
   t   __name__t
   __module__R   t   DWORDt   FILETIMEt   WCHARt   MAX_PATHt   _fields_t   propertyR3   (    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR/   q   s   ic         C` s   |  d k r t     n  d  S(   Ni    (   t   WindowsError(   t   result(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   handle_nonzero_success   s    c         C` s   d } d } | | B} d } |  } d } t j   } d } d }	 t j j | | | | t |  | |	  }
 t |
  | j } t j j	 |  | S(   ur   
        Call FormatMessage with a system error number to retrieve
        the descriptive error message.
        i   i   i    N(
   R   R   t   LPWSTRR   t   kernel32t   FormatMessageWR&   R>   t   valuet	   LocalFree(   t   errnot   ALLOCATE_BUFFERt   FROM_SYSTEMt   flagst   sourcet
   message_idt   language_idt   result_buffert   buffer_sizet	   argumentst   bytest   message(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   format_system_message   s*    
			
	R<   c           B` sD   e  Z d d   Z e d    Z e d    Z d   Z d   Z RS(   c         C` st   | d  k r t j j   } n  t |  } t j d k rN d | d  | f } n | | f } t t |   j	 |   d  S(   Ni   i    (   i   i   (
   R   R   R@   t   GetLastErrorRP   t   syst   version_infot   superR<   t   __init__(   R2   RB   t   strerrort   args(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyRU      s    c         C` s   |  j  S(   N(   RV   (   R2   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyRO      s    c         C` s   |  j  S(   N(   t   winerror(   R2   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   code   s    c         C` s   |  j  S(   N(   RO   (   R2   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   __str__   s    c         C` s   d j  t     S(   Nu*   {self.__class__.__name__}({self.winerror})(   t   formatt   vars(   R2   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   __repr__   s    N(	   R4   R5   R   RU   R;   RO   RY   RZ   R]   (    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR<      s
   
	c         C` s   |  j  d t k S(   Ni    (   t   reservedt   IO_REPARSE_TAG_SYMLINK(   t	   find_data(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   _is_symlink   s    c         C` sK   |  j  d  r |  St |   }  |  d d k sC t   d  |  }  n  d |  S(   u:  
        Paths have a max length of api.MAX_PATH characters (260). If a target path
        is longer than that, it needs to be made absolute and prepended with
        \?\ in order to work with API calls.
        See http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx for
        details.
        u   \\?\i   u   :i   (   t
   startswithR   R)   (   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   _patch_path   s    c         C` s;   t  j   j j } t j d k  r. |  j |   S|  j |  S(   u   
        format the string using variables in the caller's local namespace.
        >>> a = 3
        >>> local_format("{a:5}")
        '    3'
        i   i   (   i   i   (   t   inspectt   currentframet   f_backt   f_localsRR   RS   R[   t
   format_map(   t   stringt   context(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   local_format   s    c         C` s[   t  |   }  y t t t |     SWn. t k
 rV } d } t j t |    n Xd S(   uP   
        Assuming path is a reparse point, determine if it's a symlink.
        u,   Error accessing {path}: {orig_error.message}N(   Rc   Ra   t   nextt
   find_filesR<   t   builtinsRk   (   R   t
   orig_errort   tmpl(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR-      s    c         c` s   t    } t |  t |   } xv t r | t k r? t    n  | Vt    } t | t |   } | d k r! t   } | j t k r Pq |  q! q! Wt	 j
 j |  d S(   u  
        A pythonic wrapper around the FindFirstFile/FindNextFile win32 api.
        >>> root_files = tuple(find_files(r'c:\*'))
        >>> len(root_files) > 1
        True
        >>> root_files[0].filename == root_files[1].filename
        False
        >>> # This test might fail on a non-standard installation
        >>> 'Windows' in (fd.filename for fd in root_files)
        True
        i    N(   R/   t   FindFirstFileR&   R.   t   INVALID_HANDLE_VALUER<   t   FindNextFileRY   t   ERROR_NO_MORE_FILESR   R@   t	   FindClose(   t   spect   fdt   handlet   rest   error(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyRm      s    				c         C` s&   t  |   } | t k o% t | t @ S(   u   
        Determine if the given path is a reparse point.
        Return False if the file does not exist or the file attributes cannot
        be determined.
        (   t   GetFileAttributest   INVALID_FILE_ATTRIBUTESt   boolt   FILE_ATTRIBUTE_REPARSE_POINT(   R   Ry   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR,     s    i    i   i 	 t   SECURITY_ATTRIBUTESc           B` s2   e  Z d  e j f d e j f d e j f f Z RS(   u   lengthu   p_security_descriptoru   inherit_handle(   R4   R5   R   R6   t   LPVOIDt   BOOLEANR:   (    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR   +  s   (   t   Arrayt   create_string_buffert   c_bytet   c_ulongt   c_ushortt   sizeoft   REPARSE_DATA_BUFFERc           B` su   e  Z d  e f d e f d e f d e f d e f d e f d e f d e f d e d	 f g	 Z d
   Z d   Z RS(   u   tagu   data_lengthu   reservedu   substitute_name_offsetu   substitute_name_lengthu   print_name_offsetu   print_name_lengthu   flagsu   path_bufferi   c         C` sQ   t  t j  } t j |  j | } t |  j |  j  } t | t |   j	 j
 S(   N(   R   R   R8   t   print_name_lengthR&   t   path_buffert   print_name_offsetR(   R$   R1   RB   (   R2   t
   wchar_sizet   arr_typt   data(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   get_print_nameR  s    c         C` sQ   t  t j  } t j |  j | } t |  j |  j  } t | t |   j	 j
 S(   N(   R   R   R8   t   substitute_name_lengthR&   R   t   substitute_name_offsetR(   R$   R1   RB   (   R2   R   R   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   get_substitute_nameX  s    (   R4   R5   R   R   R   R:   R   R   (    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR   E  s   									c         C` s   t  |  d d d t t t Bd  } | t k r: t    n  t | t d d  } t	 |  } t
 | t t   } | j } | j t k s t d | j   n  t t |   | j   S(   u{   
        readlink(link) -> target
        Return a string representing the path to which the symbolic link points.
        i    i (  u+   Expected IO_REPARSE_TAG_SYMLINK, but got %dN(   t
   CreateFileR   t   OPEN_EXISTINGt   FILE_FLAG_OPEN_REPARSE_POINTt   FILE_FLAG_BACKUP_SEMANTICSRr   R<   t   reparse_DeviceIoControlt   FSCTL_GET_REPARSE_POINTR   R(   R$   R   R1   t   tagR_   R   R>   t   CloseHandleR   (   R   Rx   Ry   RN   t   p_rdbt   rdb(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR#   ^  s    		c   	   	   C` s   | d  k	 r t d   n  t | t  r9 t |  } n  | d  k	 rQ t |  n d } t |  } t | t  sx t  t j	   } t
 |  | | | | | | |  } t |  t |  | | j  S(   Nu$   overlapped handles not yet supportedi    (   R   R   t
   isinstancet   intR   t   lenR   t   AssertionErrorR   R6   t   DeviceIoControlR>   RB   (	   t   devicet   io_control_codet	   in_buffert
   out_buffert
   overlappedt   in_buffer_sizet   out_buffer_sizet   returned_bytesRy   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR     s$    	

t   CrossPlatformStLinkc           B` sS   e  Z d Z d    Z e d    Z e d    Z e d    Z e d    Z	 RS(   c         C` s   |  j  |  S(   N(   t   st_nlink(   R2   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   __call__  s    c         C` s)   |  j  d  k r |  j   n  |  j  |  S(   N(   t	   _st_nlinkR   t   _initialize(   t   clsR   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR     s    c         C` s   t  |  j S(   N(   R   R   (   R   R   (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   _standard_st_nlink  s    c   
      C` s   |  j  |  } | d k r | Sd } d } d } |  j | | | d  | d d   } | d  k rz d d l m } |    n  |  j   } |  j | |  }	 |  j |  |	 d k r d d l m } |    n  | j Sd  S(   Ni    I       i   i   (   t   WinError(	   R   R   R   t   ctypesR   t   BY_HANDLE_FILE_INFORMATIONt   GetFileInformationByHandleR   t   nNumberOfLinks(
   R   R   R   t   GENERIC_READt   FILE_SHARE_READR   t   hfileR   t   infot   rv(    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   _windows_st_nlink  s$    c         ` s@  t  s |  j |  _ n'd d l m } m } m } m } d d l m	   m
 } m } t j j |  _ |     |     | g |  j _ | |  j _ t j j |  _ | g |  j _ | |  j _ d | f   f d     Y d | f    f d     Y} | |  _ t j j |  _ | | |  g |  j _ | |  j _ |  j |  _ d  S(   Ni    (   R$   R%   t   c_void_pt	   c_wchar_p(   R6   t   HANDLEt   BOOLR7   c           ` s    e  Z d    f d   f g Z RS(   u   dwLowDateTimeu   dwHighDateTime(   R4   R5   R:   (    (   R6   (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR7     s   	R   c           ` sh   e  Z d    f d  f d  f d  f d   f d   f d   f d   f d   f d	   f g
 Z RS(
   u   dwFileAttributesu   ftCreationTimeu   ftLastAccessTimeu   ftLastWriteTimeu   dwVolumeSerialNumberu   nFileSizeHighu   nFileSizeLowu   nNumberOfLinksu   nFileIndexHighu   nFileIndexLow(   R4   R5   R:   (    (   R6   R7   (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR     s   									(   R   R   R   R   R$   R%   R   R   t   ctypes.wintypesR6   R   R   R   R@   t   CreateFileWR   t   argtypest   restypeR   R   R   R   (   R   R$   R%   R   R   R   R   R   (    (   R6   R7   s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR     s$    "	N(
   R4   R5   R   R   R   t   classmethodR   R   R   R   (    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyR     s   	(   u   islinku   lchmodu   lexistsu   linku   readlinku
   stat_nlinku   symlink(s   t
   __future__R    R   R   R   t   loggingR   t   osR   R   R   t   os.pathR   R   R	   t	   os_islinkR
   t
   os_lexistst   common.compatR   R   t
   exceptionsR   R   t   __all__R4   t   logR   t	   os_lchmodt   ImportErrorR   R   R   R   R   R@   t   CreateHardLinkWR   R   R   t   LPCWSTRR   R   t   CreateSymbolicLinkWR!   R6   t   AttributeErrorR   R    R"   R#   R$   R%   R&   R'   R(   Rd   R)   R*   RR   t   _vendor.auxlib._vendorR+   t   movesRn   R9   R_   R|   R~   t   NULLRt   R/   t   LPWIN32_FIND_DATAt   FindFirstFileWRq   R?   R   t   FindNextFileWRs   R   RB   Rr   t   GetFileAttributesWR{   R>   RP   R<   Ra   Rc   Rk   R-   Rm   R,   R   R   R   R   t   LPDWORDt   LPOVERLAPPEDR   t   LPSECURITY_ATTRIBUTESR   R   R   R   R   R   R   R   R   R   R   R   t   objectR   t
   stat_nlink(    (    (    s7   lib/python2.7/site-packages/conda/gateways/disk/link.pyt   <module>   s   ""	
	
			4					#							.	U