
    si.5                     >   S r SSKrSSK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Jr  Sr\" \5      r\R,                  R.                  S:H  r SSKJr  \r\(       d  SSKJrJr  \r\rOSSKJrJ r   \RB                  RD                  r#\ RH                  \#l%        \ RL                  \ RL                  \ RN                  /\#l(         \RB                  RR                  r*\ RH                  \*l%        \ RL                  \ RL                  \ RV                  /\*l(        S r-S r.\-r\.r\(       a  \(       d  SSKJ/r/  \r
\r\/r/gSSK0r0SSK1r1SSKrSSKJ2r2J3r3J4r4J5r5J6r6JrJ r   SSKJ7r7  SSKJ8r8  S r
S rSr9Sr:Sr;Sr<Sr=Sr> " S S\35      r?\2" \?5      r@\RB                  R                  rB\ R                  \@4\Bl(        \ R                  \Bl%        \RB                  R                  rF\ R                  \@4\Fl(        \ R                  \Fl%        \ R                  " S 5      R                  rI\RB                  R                  rK\ RV                  \Kl%        \ R                  4\Kl(        S! rLS" rM " S# S$\0R                  5      rNS% rOS& rPS' rQS( rRS) rSS* rTSrUS+rVS,rWS-rX\2" \ RV                  5      rY\ RN                  rZ " S. S/\35      r[\2" \[5      r\\RB                  R                  r^\ R                  \ RV                  \ RV                  \\\ RV                  \ RV                  \ R                  4\^l(        \ R                  \^l%        \RB                  R                  r_\ R                  4\_l(        \ R                  \_l%        SS0KJ`r`JaraJbrbJcrcJdrdJere   " S1 S2\35      rfS3 r/\RB                  R                  rg\ R                  \ RV                  \ RN                  \ RV                  \ RN                  \ RV                  \Y\Z/\gl(        \ RH                  \gl%         S5S4 jrhg! \ a    S r GNf = f! \, a    Sr* GNf = f)6a  Disk utility functions for symlinking files and folders.

Portions of the code within this module are taken from https://github.com/jaraco/jaraco.windows
which is MIT licensed by Jason R. Coombs.

https://github.com/jaraco/skeleton/issues/1#issuecomment-285448440
    N)	getLogger)chmod)abspathisdir)islink)lexists   )on_win)CondaOSError
ParseError)r   lchmodr   linkreadlinksymlinkpypy)r   c                 <    [        U 5      (       d  [        X5        g g N)r   os_chmod)pathmodes     8lib/python3.13/site-packages/conda/gateways/disk/link.pyr   r   !   s     d||T      )r   r   )windllwintypesc                 H    [        XS5      (       d  [        SU  SU 35      eg)z;Equivalent to os.link, using the win32 CreateHardLink call.Nzwin32 hard link failed
  src: 
  dst: )CreateHardLinkr   srcdsts     r   win_hard_linkr!   ?   s-    c--!@YseTUU .r   c                 ~    [         c  [        S5      e[        X[        U 5      5      (       d  [        SU  SU 35      eg)zBEquivalent to os.symlink, using the win32 CreateSymbolicLink call.Nzwin32 soft link not supportedzwin32 soft link failed
  src: r   )CreateSymbolicLinkr   r   r   s     r   win_soft_linkr$   D   sC    %>??!#E#J77!@YseTUU 8r   )r   )POINTER	Structurebyrefc_uint64castr   r   )getcwd)isfilec                 <    [        U 5      =(       a    [        U 5      $ )z(Determine if the given path is a symlink)is_reparse_point
is_symlinkr   s    r   r   r   ^   s    %:*T*::r   c                 j    [        U 5      (       a  g[        U 5      (       a  g[        U 5      (       a  gg)NTF)r   r   r+   r/   s    r   r   r   b   s)    $<<;;$<<r   i  l     @ l    i      c            
          \ rS rSrS\R
                  4S\R                  4S\R                  4S\R                  4S\R
                  S-  4S\R
                  S-  4S	\R                  \-  4S
\R                  S-  4/r	\
S 5       rSrg)WIN32_FIND_DATAr   file_attributescreation_timelast_access_timelast_write_timefile_size_words   reservedfilenamealternate_filename   c                 \    [        U R                  [        [        5      5      R                  $ r   )r)   r9   r%   r(   contentsselfs    r   	file_sizeWIN32_FIND_DATA.file_size~   s     ,,gh.?@IIIr    N)__name__
__module____qualname____firstlineno__r   DWORDFILETIMEWCHARMAX_PATH_fields_propertyrC   __static_attributes__rE   r   r   r3   r3   r   s    /h//0!2!23 1 12 23!+,(23!8>>B#67	
 
	J 
	Jr   r3   c                 $    U S:X  a
  [        5       eg Nr   )OSError)results    r   handle_nonzero_successrV      s    Q;)O r   c           	         SnSnX-  nSnU nSn[         R                  " 5       nSnSn	[        R                  R	                  UUUU[        U5      UU	5      n
[        U
5        UR                  n[        R                  R                  U5        U$ )zZ
Call FormatMessage with a system error number to retrieve
the descriptive error message.
   i   Nr   )	r   LPWSTRr   kernel32FormatMessageWr'   rV   value	LocalFree)errnoALLOCATE_BUFFERFROM_SYSTEMflagssource
message_idlanguage_idresult_bufferbuffer_size	argumentsbytesmessages               r   format_system_messagerj      s        -
 )	..- 
 	u%%%!!-0r   c                   X   ^  \ rS rSrSU 4S jjr\S 5       r\S 5       rS rS r	Sr
U =r$ )	WindowsError   c                    > Uc  [         R                  R                  5       n[        U5      nSUS U4n[        TU ]  " U6   g rS   )r   rZ   GetLastErrorrj   super__init__)rB   r\   strerrorargs	__class__s       r   rq   WindowsError.__init__   s?    }446,U3Hhe+DGd#r   c                     U R                   $ r   )rr   rA   s    r   ri   WindowsError.message       == r   c                     U R                   $ r   )winerrorrA   s    r   codeWindowsError.code   rx   r   c                     U R                   $ r   )ri   rA   s    r   __str__WindowsError.__str__   s    <<r   c                 6    SR                   " S0 [        5       D6$ )Nz*{self.__class__.__name__}({self.winerror})rE   )formatvarsrA   s    r   __repr__WindowsError.__repr__   s    ?FFPPPr   rE   r   )rF   rG   rH   rI   rq   rO   ri   r{   r~   r   rP   __classcell__)rt   s   @r   rl   rl      sA    	$ 
	! 
	! 
	! 
	!	 	Q 	Qr   rl   c                 .    U R                   S   [        :H  $ rS   )r;   IO_REPARSE_TAG_SYMLINK)	find_datas    r   _is_symlinkr      s    !!!$(>>>r   c                     U R                  S5      (       a  U $ [        U 5      n U S   S:X  d  [        5       SS U -   n SU -   $ )a  
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.
z\\?\   :Nr:   )
startswithr   r*   r/   s    r   _patch_pathr      sI     ??9%%Kt}Aw#~8BQ<$&D4r   c                 v    [         R                  " 5       R                  R                  nU R	                  U5      $ )zFormat the string using variables in the caller's local namespace.

.. code-block:: pycon
    >>> a = 3
    >>> local_format("{a:5}")
    '    3'
)inspectcurrentframef_backf_locals
format_map)stringcontexts     r   local_formatr      s/     &&(//88  ))r   c                     [        U 5      n  [        [        [        U 5      5      5      $ ! [         a  nSn[	        [        U5      5      eSnAff = f)z>Assuming path is a reparse point, determine if it's a symlink.z,Error accessing {path}: {orig_error.message}N)r   r   next
find_filesrT   r   )r   
orig_errortmpls      r   r.   r.      sK    4 	.tJt$4566 	.AD,t,--	.s   * 
AA

Ac              #   J  #    [        5       n[        U [        U5      5      n U[        :X  a
  [	        5       eUv   [        5       n[        U[        U5      5      nUS:X  a!  [        5       nUR                  [        :X  a  OUeM`  [        R                  R                  U5        g7f)a<  
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
r   N)r3   FindFirstFiler'   INVALID_HANDLE_VALUErT   FindNextFilerl   r{   ERROR_NO_MORE_FILESr   rZ   	FindClose)specfdhandlereserrors        r   r   r      s      tU2Y/--iH "BvuRy1Cax$::!44K  	!!&)s   B!B#c                 \    [        U 5      nU[        :g  =(       a    [        U[        -  5      $ )z
Determine if the given path is a reparse point.
Return False if the file does not exist or the file attributes cannot
be determined.
)GetFileAttributesINVALID_FILE_ATTRIBUTESboolFILE_ATTRIBUTE_REPARSE_POINT)r   r   s     r   r-   r-     s1      %-- 
$..3
 	
r   i    i   i 	 c                   f    \ rS rSrS\R
                  4S\R                  4S\R                  44rSr	g)SECURITY_ATTRIBUTESi%  lengthp_security_descriptorinherit_handlerE   N)
rF   rG   rH   rI   r   rJ   LPVOIDBOOLEANrN   rP   rE   r   r   r   r   %  s/    x~~&$hoo6x//0
r   r   )Arrayc_bytec_ulongc_ushortcreate_string_buffersizeofc                   `    \ rS rSrS\4S\4S\4S\4S\4S\4S\4S	\4S
\S-  4/	rS rS r	Sr
g)REPARSE_DATA_BUFFERi@  tagdata_lengthr;   substitute_name_offsetsubstitute_name_lengthprint_name_offsetprint_name_lengthra   path_bufferr   c                    [        [        R                  5      n[        R                  U R                  U-  -  n[	        U R
                  U R                  5      n[        U[        U5      5      R                  R                  $ r   )r   r   rL   r   r'   r   r   r)   r%   r@   r\   rB   
wchar_sizearr_typdatas       r   get_print_name"REPARSE_DATA_BUFFER.get_print_nameM  s_    /Jnn(>(>*(LMG))4+A+ABDgg./88>>>r   c                    [        [        R                  5      n[        R                  U R                  U-  -  n[	        U R
                  U R                  5      n[        U[        U5      5      R                  R                  $ r   )r   r   rL   r   r'   r   r   r)   r%   r@   r\   r   s       r   get_substitute_name'REPARSE_DATA_BUFFER.get_substitute_nameS  s_    /Jnn(C(Cz(QRG))4+F+FGDgg./88>>>r   rE   N)rF   rG   rH   rI   r   r   r   rN   r   r   rP   rE   r   r   r   r   @  s_    GH%"%x0%x0 (+ (+gFQJ'

	?	?r   r   c           	         [        U SSS[        [        [        -  S5      nU[        :X  a
  [        5       e[        U[        SS5      n[        U5      n[        U[        [        5      5      nUR                  nUR                  [        :X  d  [        SUR                  -  5      e[!        [#        U5      5        UR%                  5       $ )zcReturn a string representing the path to which the symbolic link points.

readlink(link) -> target
r   Ni (  z+Expected IO_REPARSE_TAG_SYMLINK, but got %d)
CreateFileOPEN_EXISTINGFILE_FLAG_OPEN_REPARSE_POINTFILE_FLAG_BACKUP_SEMANTICSr   rT   reparse_DeviceIoControlFSCTL_GET_REPARSE_POINTr   r)   r%   r   r@   r   r   r   rV   CloseHandler   )r   r   r   rh   p_rdbrdbs         r   r   r   Y  s    
 (+EE
 )))O%f.EtUS$S)UG$789nnww00JSWWTUU{623&&((r   c           
      l   Ub  [        S5      e[        U[        5      (       a  [        U5      nUb  [	        U5      OSn[	        U5      n[        U[
        5      (       d  [        S5      e[        R                  " 5       n[        U UUUUUUU5      n[        U5        [        U5        US UR                   $ )Nz$overlapped handles not yet supportedr   zout_buffer must be Array)NotImplementedError
isinstanceintr   lenr   	TypeErrorr   rJ   DeviceIoControlrV   r\   )	deviceio_control_code	in_buffer
out_buffer
overlappedin_buffer_sizeout_buffer_sizereturned_bytesr   s	            r   r   r     s     !%&LMMj#&&-j9J+4+@Yaj/*e,,677!)	
 	s#~.0N0011r   r   )i__doc__sysloggingr   osr   r   os.pathr   r   r   	os_islinkr   
os_lexistscommon.compatr
   
exceptionsr   r   __all__rF   logimplementationnamePYPYr   	os_lchmodImportErrorr   r   ctypesr   r   rZ   CreateHardLinkWr   BOOLrestypeLPCWSTRr   argtypesCreateSymbolicLinkWr#   rJ   AttributeErrorr!   r$   r   builtinsr   r%   r&   r'   r(   r)   r*   r+   rM   r   r   r   NULLr   r3   LPWIN32_FIND_DATAFindFirstFileWr   rY   HANDLEFindNextFileWr   r   r\   r   GetFileAttributesWr   rV   rj   rl   r   r   r   r.   r   r-   r   r   r   r   LPDWORDLPOVERLAPPEDr   LPSECURITY_ATTRIBUTESCreateFileWr   r   r   r   r   r   r   r   r   r   r   rE   r   r   <module>r	     s       " ' ) # 2
H
&(
!&F  DG (__44N%]]N'//1A1A8??SN	"#__@@%-]]"NN'
#V
V DG 	4FGH RRR; H'(#( DJ) J   0OO22M&oo/@AM$OOM??00L%__.?@L#++L#??2.44:: ("*//!3!FQx,, Q0?  	*.*<	
 M#- !*%hnn%G??L
i 
 $$78,,JJ "J//--K$OO-K"**KUU?i ?2): oo55O	 O 'mmO DH2I  !!!:  "!"s%   P  AP  	PPPP