
    6h                    <   % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJr  SSKJr  SSKJrJrJrJrJr  \R>                  (       a  SSKJ r!  \" SS	S
9r"\" SSS
9r#\\$/\\%   4   r&S"S jr' " S S\RP                  5      r) " S S\)5      r*\*r+S\,S'    " S S\)\RP                  5      r- " S S\-\)5      r.\.r/S\,S'    " S S\-5      r0 " S S\RP                  5      r1 " S S\15      r2 " S S	5      r3 " S  S!\15      r4g)#    )annotationsN)AnyBinaryIOCallableDictIterableIteratorListMutableMappingOptionalSetTupleTypeTypeVarUnion   )_)encodingerrorpathutilpycompatutil)ui_Tbackgroundfilecloserbackgroundfilecloser)bound_Tclosewrapbaseclosewrapbasec                   ^ ^ UU 4S jnU" 5       (       d3  [         R                  " [         R                  " T 5      T 5        U" 5         gg)zAvoid file stat ambiguity forcibly

This function causes copying ``path`` file, if it is owned by
another (see issue5418 and issue5584 for detail).
c                    > [         R                  R                  T5      n U R                  T5      (       + =(       d    U R	                  TT5      $ N)r   filestatfrompathisambig
avoidambig)newstatoldstatpaths    //usr/lib/python3/dist-packages/mercurial/vfs.pycheckandavoid"_avoidambig.<locals>.checkandavoid?   s;    --((.??7++Pw/A/A$/PP    N)r   rename
mktempcopy)r(   r'   r*   s   `` r)   _avoidambigr/   8   s5    Q
 ?? 	DOOD)40	 r,   c                     \ rS rSr% SrSrS\S'   SrS\S'   S	\S
'   \R                  S>S?S jj5       r
\R                  S@S j5       r\R                  SAS j5       rSBS jrS>SCS jjr\R                   S 5       rSBS jrS>SCS jjr SD       SES jjr  SF         SGS jjrSHS jrSBS jrSIS jrSBS jrSJSKS jjrSLS jrSJSKS jjrSJSKS jjrSJSKS jjrSJSKS jjrSMS  jr SMS! jr!SNS" jr"SJSKS# jjr#SJSOS$ jjr$SJSKS% jjr%SJSPS& jjr&SQSRS' jjr' SS     STS( jjr(SUS) jr)SJSRS* jjr*   SV       SWS+ jjr+ SX   SYS, jjr,SBS- jr-SDSZS. jjr.SBS/ jr/SJSRS0 jjr0SJSRS1 jjr1   S[       S\S2 jjr2S]S3 jr3SJSOS4 jjr4SJSRS5 jjr5SJSKS6 jjr6   S^       S_S7 jjr7 SS     S`S8 jjr8 SS     SaS9 jjr9\:Rv                   Sb     ScS: jj5       r<SdS; jr=      SeS< jr>S=r?g)fabstractvfsK   z+Abstract base class; cannot be instantiated   /bytes_dir_sepTint
createmodebool_chmodc                    g r!    )selfr(   modekwargss       r)   __call__abstractvfs.__call__`       r,   c                    g r!   r;   r<   r(   r=   s      r)   
_auditpathabstractvfs._auditpathd   rA   r,   c                    g r!   r;   r<   r(   insidefs      r)   joinabstractvfs.joinh   rA   r,   c                F     U R                  U5      $ ! [         a     gf = f)z3gracefully return an empty string for missing filesr,   )readFileNotFoundErrorr<   r(   s     r)   tryreadabstractvfs.tryreadl   s*    	99T?"  		s    
  c                D     U R                  XS9$ ! [         a     / $ f = f)z2gracefully return an empty array for missing filesr=   )	readlinesrM   rC   s      r)   tryreadlinesabstractvfs.tryreadlinest   s/    	>>$>22  			s    
c                    U R                   $ )zOpen ``path`` file, which is relative to vfs root.

Newly created directories are marked as "not to be indexed by
the content indexing service", if ``notindexed`` is specified
for "write" mode access.
)r?   r<   s    r)   openabstractvfs.open|   s     }}r,   c                j    U " US5       nUR                  5       sS S S 5        $ ! , (       d  f       g = f)N   rb)rL   )r<   r(   fps      r)   rL   abstractvfs.read   s#    $"779 s   $
2c                d    U " XS9 nUR                  5       sS S S 5        $ ! , (       d  f       g = f)NrR   )rS   )r<   r(   r=   r\   s       r)   rS   abstractvfs.readlines   s!    $"b<<> #""s   !
/c                r    U " US4SU0UD6 nUR                  U5      sS S S 5        $ ! , (       d  f       g = f)N   wbbackgroundclosewrite)r<   r(   datarb   r>   r\   s         r)   rd   abstractvfs.write   s2     $II&IR88D> JIIs   (
6c                h    U " XUS9 nUR                  U5      sS S S 5        $ ! , (       d  f       g = f)N)r=   
notindexed)
writelines)r<   r(   re   r=   rh   r\   s         r)   ri   abstractvfs.writelines   s(     $j9R==& :99s   #
1c                l    U " US5       nUR                  U5      sS S S 5        $ ! , (       d  f       g = f)Ns   abrc   )r<   r(   re   r\   s       r)   appendabstractvfs.append   s%    $"88D> s   %
3c                @    [         R                  R                  U5      $ )zzreturn base element of a path (as os.path.basename would do)

This exists to allow handling of strange encoding if needed.)osr(   basenamerN   s     r)   rp   abstractvfs.basename   s     ww%%r,   c                N    [         R                  " U R                  U5      U5      $ r!   )ro   chmodrI   rC   s      r)   rs   abstractvfs.chmod   s    xx		$..r,   c                @    [         R                  R                  U5      $ )z|return dirname element of a path (as os.path.dirname would do)

This exists to allow handling of strange encoding if needed.)ro   r(   dirnamerN   s     r)   rv   abstractvfs.dirname   s     wwt$$r,   Nc                ^    [         R                  R                  U R                  U5      5      $ r!   )ro   r(   existsrI   rN   s     r)   ry   abstractvfs.exists       ww~~diio..r,   c                .    [         R                  " U5      $ r!   )r   fstat)r<   r\   s     r)   r}   abstractvfs.fstat   s    zz"~r,   c                ^    [         R                  R                  U R                  U5      5      $ r!   )ro   r(   isdirrI   rN   s     r)   r   abstractvfs.isdir   s    ww}}TYYt_--r,   c                ^    [         R                  R                  U R                  U5      5      $ r!   )ro   r(   isfilerI   rN   s     r)   r   abstractvfs.isfile   r{   r,   c                ^    [         R                  R                  U R                  U5      5      $ r!   )ro   r(   islinkrI   rN   s     r)   r   abstractvfs.islink   r{   r,   c                     U R                  U5      nUR                  n[        R                  " U5      =(       d    [        R
                  " U5      $ ! [         a     gf = f)z`return whether path is a regular file or a symlink

Unlike isfile, this doesn't follow symlinks.F)lstatOSErrorst_modestatS_ISREGS_ISLNK)r<   r(   str=   s       r)   isfileorlinkabstractvfs.isfileorlink   sQ    	D!B zz||D!7T\\$%77  		s   A 
AAc                F   Sn[        U5       HM  u  p4[        R                  R                  U5      (       d"  UR	                  U R
                  5      (       d  MK  UnMO     US:w  a  XS  nU Vs/ s H  oD(       d  M  UPM     nnU R
                  R                  U5      $ s  snf Nr   )	enumeratero   r(   isabs
startswithr5   rI   )r<   pathsroot_idxidxps        r)   _joinabstractvfs._join   s    &FCww}}Q1<<#>#> ' q=)$E!'EqQE'}}!!%(( (s   -
B;Bc                     U R                   " U6 $ )zjoin various elements of a path together (as os.path.join would do)

The vfs base is not injected so that path stay relative. This exists
to allow handling of strange encoding if needed.)r   )r<   r   s     r)   reljoinabstractvfs.reljoin   s    
 zz5!!r,   c                @    [         R                  R                  U5      $ )zzsplit top-most element of a path (as os.path.split would do)

This exists to allow handling of strange encoding if needed.)ro   r(   splitrN   s     r)   r   abstractvfs.split   s     ww}}T""r,   c                ^    [         R                  R                  U R                  U5      5      $ r!   )ro   r(   lexistsrI   rN   s     r)   r   abstractvfs.lexists   s    wwtyy//r,   c                L    [         R                  " U R                  U5      5      $ r!   )ro   r   rI   rN   s     r)   r   abstractvfs.lstat       xx		$((r,   c                l    [         R                  " U R                  U5      5      nUSL=(       a    US:g  $ )a  return True if it is safe to read a file content as mmap

This focus on the file system aspect of such safety, the application
logic around that file is not taken into account, so caller need to
make sure the file won't be truncated in a way that will create SIGBUS
on access.


The initial motivation for this logic is that if mmap is used on NFS
and somebody deletes the mapped file (e.g. by renaming on top of it),
then you get SIGBUS, which can be pretty disruptive: we get core dump
reports, and the process terminates without writing to the blackbox.

Instead, in this situation we prefer to read the file normally.
The risk of ESTALE in the middle of the read remains, but it's
smaller because we read sooner and the error should be reported
just as any other error.

Note that python standard library does not offer the necessary function
to detect the file stem bits. So this detection rely on compiled bits
and is not available in pure python.
Ns   nfs)r   	getfstyperI   )r<   r(   fstypes      r)   is_mmap_safeabstractvfs.is_mmap_safe   s/    4 		$0T!6f&66r,   c                L    [         R                  " U R                  U5      5      $ r!   )ro   listdirrI   rN   s     r)   r   abstractvfs.listdir  s    zz$))D/**r,   c                N    [         R                  " U R                  U5      U5      $ r!   )r   makedirrI   )r<   r(   rh   s      r)   r   abstractvfs.makedir  s    ||DIIdOZ88r,   c                N    [         R                  " U R                  U5      U5      $ r!   )r   makedirsrI   rC   s      r)   r   abstractvfs.makedirs  s     }}TYYt_d33r,   c                L    [         R                  " XR                  U5      5      $ r!   )r   makelockrI   )r<   infor(   s      r)   r   abstractvfs.makelock  s    }}T99T?33r,   c                L    [         R                  " U R                  U5      5      $ r!   )ro   mkdirrI   rN   s     r)   r   abstractvfs.mkdir  r   r,   c                    [         R                  " XU R                  U5      S9u  pE[        R                  " U5      u  pgU(       a!  U[
        R                  R                  X75      4$ XG4$ )N)suffixprefixdir)r   mkstemprI   r   r   ro   r(   )r<   r   r   r   fdnamednamefnames           r)   r   abstractvfs.mkstemp  sX     ##diin
 zz$'rww||C///9r,   c                N    [         R                  " U R                  U5      X#5      $ r!   )r   r   rI   )r<   r(   r   skips       r)   readdirabstractvfs.readdir+  s     ||DIIdOT88r,   c                L    [         R                  " U R                  U5      5      $ r!   )r   readlockrI   rN   s     r)   r   abstractvfs.readlock0      }}TYYt_--r,   c                2   U R                  US5        U R                  U5      nU R                  U5      nU(       a  [        R                  R	                  U5      OSn[        R
                  " XE5        U(       a  UR                  (       a  [        XV5        ggg)a|  Rename from src to dst

checkambig argument is used with util.filestat, and is useful
only if destination file is guarded by any lock
(e.g. repo.lock or repo.wlock).

To avoid file stat ambiguity forcibly, checkambig=True involves
copying ``src`` file, if it is owned by another. Therefore, use
checkambig=True only in limited cases (see also issue5418 and
issue5584 for detail).
   wN)rD   rI   r   r"   r#   r-   r   r/   )r<   srcdst
checkambigsrcpathdstpathr'   s          r)   r-   abstractvfs.rename3  sh     	T"))C.))C.5?$--((1TG%w||) $7r,   c                L    [         R                  " U R                  U5      5      $ r!   )r   readlinkrI   rN   s     r)   r   abstractvfs.readlinkI  r   r,   c                L    [         R                  " U R                  U5      5      $ )z7Remove a leaf directory and all empty intermediate ones)r   
removedirsrI   rN   s     r)   r   abstractvfs.removedirsL  s    tyy//r,   c                L    [         R                  " U R                  U5      5      $ )zRemove an empty directory.)ro   rmdirrI   rN   s     r)   r   abstractvfs.rmdirP  s    xx		$((r,   c                    U(       a  SS jnOS n [         R                  " U R                  U5      X$S9$ ! [         a'    [         R                  " U R                  U5      X$S9s $ f = f)zaRemove a directory tree recursively

If ``forcibly``, this tries to remove READ-ONLY files, too.
c                T   U [         R                  La  e [         R                  " U5      nUR                  [        R                  -  S:w  a  e [         R
                  " U[        R                  " UR                  5      [        R                  -  5        [         R                  " U5        g r   )ro   remover   r   S_IWRITErs   S_IMODE)functionr(   excinfoss       r)   onexc!abstractvfs.rmtree.<locals>.onexc`  sg    
 299,GGDMII-!3t||AII6FG		$r,   c                     g r!   r;   )argss    r)   r   r   p  s    r,   )ignore_errorsr   )r   onerror)r   r   r(   strr   	Exception)shutilrmtreerI   	TypeError)r<   r(   r   forciblyr   s        r)   r   abstractvfs.rmtreeT  sc       		==		$}   	==		$} 	s   #6 .A'&A'c                N    [         R                  " U R                  U5      X#5      $ r!   )r   setflagsrI   )r<   r(   lxs       r)   r   abstractvfs.setflags~  s    }}TYYt_a33r,   c                L    [         R                  " U R                  U5      5      $ r!   )ro   r   rI   rN   s     r)   r   abstractvfs.stat  s    wwtyy''r,   c                L    [         R                  " U R                  U5      5      $ r!   )r   unlinkrI   rN   s     r)   r   abstractvfs.unlink  s    {{499T?++r,   c                L    [         R                  " U R                  U5      5      $ )z7Attempt to remove a file, ignoring missing file errors.)r   	tryunlinkrI   rN   s     r)   r  abstractvfs.tryunlink  s    ~~diio..r,   c                J    [         R                  " U R                  U5      X#S9$ )N)ignoremissingr   )r   
unlinkpathrI   )r<   r(   r  r   s       r)   r  abstractvfs.unlinkpath  s"     IIdO=
 	
r,   c                N    [         R                  " U R                  U5      U5      $ r!   )ro   utimerI   )r<   r(   ts      r)   r  abstractvfs.utime  s     xx		$++r,   c              #    #    [         R                  R                  U R                  S5      5      n[	        [
        R                  " U5      5      n[         R                  " U R                  U5      US9 H  u  pVnXTS Xg4v   M     g7f)a  Yield (dirpath, dirs, files) tuple for each directory under path

``dirpath`` is relative one from the root of this vfs. This
uses ``os.sep`` as path separator, even you specify POSIX
style ``path``.

"The root of this vfs" is represented as empty ``dirpath``.
N)r   )ro   r(   normpathrI   lenr   normasprefixwalk)r<   r(   r   root	prefixlendirpathdirsfiless           r)   r  abstractvfs.walk  sm      ww		$0 --d34	$&GGDIIdOW$M G5:&44 %Ns   BBc              #  n  #    [         R                  " 5       [         R                  " 5       La  Sv   g[        U SU 5      n[        USS5      (       a  [        R
                  " [        S5      5      e[        XS9 n UUl        Uv   SUl         SSS5        g! SUl        f = f! , (       d  f       g= f7f)zAllow files to be closed asynchronously.

When this context manager is active, ``backgroundclose`` can be passed
to ``__call__``/``open`` to result in the file possibly being closed
asynchronously, on a background thread.
Nvfs_backgroundfileclosers-   can only have 1 active background file closer)expectedcount)		threadingcurrent_threadmain_threadgetattrr   Abortr   r   r  )r<   r   r  r  bfcs        r)   backgroundclosingabstractvfs.backgroundclosing  s      ##%Y-B-B-DDdE4(3/66++BC  ""Bc ) 	  ) CB  ) CBs6   A8B5:B$<BB$	B5	B!!B$$
B2.B5c                    g)z1generic hook point to lets fncache steer its stewNr;   rN   s     r)   register_fileabstractvfs.register_file  s    r,   c                J   U R                  U5      nU R                  US5        U R                  U5        [        R                  " U5      u  pEXB;  a2  [        R
                  " X@R                  S5        UR                  U5        SnU R                  b  U R                  S-  nX64$ )at  make sure we are ready to write a file from a stream clone

The "known_directories" variable is here to avoid trying to create the
same directories over and over during a stream clone. It will be
updated by this function.

return (path, mode)::

    <path> is the real file system path content should be written to,
    <mode> is the file mode that need to be set if any.
ra   TN  )rI   rD   r#  r   r   r   r7   add)r<   r(   known_directories	real_pathrv   rp   r=   s          r)   prepare_streamed_file!abstractvfs.prepare_streamed_file  s     IIdO		5)4  JJy1+MM'??D9!!'*??&??U*Dr,   r;   r[   r(   r4   r=   r4   returnr   r(   r4   r=   r4   r.  Noner(   Optional[bytes]rH   r4   r.  r4   )r(   r4   r.  r4   )r(   r4   r=   r4   r.  List[bytes])F)r(   r4   re   r4   rb   r8   r.  r6   )ra   F)
r(   r4   re   zIterable[bytes]r=   r4   rh   r8   r.  r0  )r(   r4   re   r4   r.  r6   )r(   r4   r=   r6   r.  r0  r!   )r(   r2  r.  r8   )r\   r   r.  os.stat_result)r   r4   r.  r4   )r(   r4   r.  zTuple[bytes, bytes])r(   r2  r.  r4  )r(   r2  r.  r3  NT)r(   r2  r.  r0  )NN)r(   r2  r=   Optional[int]r.  r0  )r   r4   r(   r4   r.  r0  )r,   s   tmpN)r   r4   r   r4   r   r2  r.  zTuple[int, bytes])NNN)r(   r2  r.  r   )r   r4   r   r4   r   r8   r.  r0  )NFF)r(   r2  r   r8   r   r8   r.  r0  )r(   r4   r   r8   r   r8   r.  r0  )NFT)r(   r2  r  r8   r   r8   r.  r0  )r(   r2  r	  zOptional[Tuple[int, int]]r.  r0  )r(   r2  r   zOptional[_OnErrorFn]r.  z0Iterator[Tuple[bytes, List[bytes], List[bytes]]])r   uimod.uir  r6   r.  z(Iterator[Optional[backgroundfilecloser]])r(   r4   r.  r0  )r(   r4   r(  z
Set[bytes]r.  zTuple[bytes, Optional[int]])@__name__
__module____qualname____firstlineno____doc__r5   __annotations__rust_compatibleabcabstractmethodr?   rD   rI   rO   rT   r   propertycacherX   rL   rS   rd   ri   rl   rp   rs   rv   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r  r  r  r  
contextlibcontextmanagerr   r#  r*  __static_attributes__r;   r,   r)   r1   r1   K   s   5 He O OL 	  	  	  
 "
 AF""!&"9="	"  '' ' 	'
 ' 
'"&/%/.//	8)"#0)7:+9 CG4#42?4	4
4)
 #	  	
 
, =A9#9	9
.*,.0) !%#	(( ( 	(
 
(T4(,/ !%#	

 
 	

 

 LP,#,/H,	, MQ5#55I5	95$ 13+.	1 @@.8	$r,   r1   c                  T   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'       S           SS jjr\R                  SS j5       r	\R                  SS j5       r
SS jrSS jr      SS jr        S                    S!S jjrS"S jrS#S jrSrg)$r  i  aS  Operate files relative to a base directory

This class is used to hide the details of COW semantics and
remote file access from higher level code.

'cacheaudited' should be enabled only if (a) vfs object is short-lived, or
(b) the base directory is managed by hg and considered sort-of append-only.
See pathutil.pathauditor() for details.
zDUnion[pathutil.pathauditor, Callable[[bytes, Optional[bytes]], Any]]auditr4   baser6  r7   Dict[bytes, Any]optionsr8   _auditzOptional[bool]_trustnlinkc                8   U(       a  [         R                  " U5      nU(       a  [        R                  R	                  U5      nXl        X l        U(       a%  [        R                  " U R
                  US9U l	        O
SS jU l	        S U l
        S U l        0 U l        g )N)cachedc                    gr5  r;   )r(   r=   s     r)   <lambda>vfs.__init__.<locals>.<lambda>  s    r,   r!   )r   
expandpathro   r(   realpathrI  rL  r   pathauditorrH  r7   rM  rK  )r<   rI  rH  cacheauditedrS  rT  s         r)   __init__vfs.__init__  sn     ??4(D77##D)D	!--diiMDJ5DJr,   c                B    [         R                  " U R                  5      $ r!   )r   	checklinkrI  rW   s    r)   _cansymlinkvfs._cansymlink      ~~dii((r,   c                B    [         R                  " U R                  5      $ r!   )r   	checkexecrI  rW   s    r)   r9   
vfs._chmod  r]  r,   c                    U R                   b  U R                  (       d  g [        R                  " XR                   S-  5        g )Nr&  )r7   r9   ro   rs   )r<   r   s     r)   _fixfilemodevfs._fixfilemode  s*    ??"$++
./r,   c                   U R                   (       a  [        R                  R                  U5      (       aI  UR	                  U R
                  5      (       a)  [        R                  R                  XR
                  5      n[        R                  " U5      nU(       a  [        R                  " SX14-  5      eU R                  XS9  g g )Ns   %s: %rrR   )rL  ro   r(   r   r   rI  relpathr   checkosfilenamer   r  rH  )r<   r(   r=   rs       r)   rD   vfs._auditpath!  s    ;;ww}}T""ttyy'A'AwwtYY7$$T*Akk)qi"788JJtJ' r,   c                J    [         R                  " [        R                  " U5      5       HD  nX1;   a  X   nO.[         R                  R                  U R                  X25      nXAU'   U(       a  MD    g   U R                  U5      $ ! [        [        R                  4 a     gf = f)a  return True if the path is a regular file or a symlink and
the directories along the path are "normal", that is
not symlinks or nested hg repositories.

Ignores the `_audit` setting, and checks the directories regardless.
`dircache` is used to cache the directory checks.
F)r   finddirs_rev_norootr   	localpathrU  _checkfs_existsrI  r   r   r  r   )r<   dircacher(   r   ress        r)   isfileorlink_checkdirvfs.isfileorlink_checkdir*  s    	"66t~~d7KL%"*C"..>>		6C (+V$s  M   && % 		s   A*B 0B 2B B"!B"c
                f   U(       a  U R                  X5        U R                  U5      n
SU;  a  US-  nSnUS;  GaH  [        R                  " U
5      u  pU(       Ga(  U(       aH  U(       a!  [        R                  " XR
                  U5        [        R                  " XU R
                  US9$  SU;   a  [        R                  " U
5        SnO=[        R                  " U
5         [        R                  " U
5      nUS:  a  SnS	S	S	5        US:  av  U R                  c'  US:  =(       d    [        R                  " U
5      U l        US:  d  U R                  (       d+  [        R                  " [        R                  " U
5      U
5        [        R                  " XU	S
9nUS:X  a  U R                  U
5        U(       a3  US;   a"  [         R"                  " [%        S5      U-  5      e['        U5      nU(       aq  [(        R*                  " 5       [(        R,                  " 5       L aF  U R.                  (       d  [         R"                  " [%        S5      5      e[1        UU R.                  5      nU$ ! , (       d  f       GNk= f! [         a.    SnU(       a!  [        R                  " XR
                  U5         GNf = f)a  Open ``path`` file, which is relative to vfs root.

By default, parent directories are created as needed. Newly created
directories are marked as "not to be indexed by the content indexing
service", if ``notindexed`` is specified for "write" mode access.
Set ``makeparentdirs=False`` to not create directories implicitly.

If ``backgroundclose`` is passed, the file may be closed asynchronously.
It can only be used if the ``self.backgroundclosing()`` context manager
is active. This should only be specified if the following criteria hold:

1. There is a potential for writing thousands of files. Unless you
   are writing thousands of files, the performance benefits of
   asynchronously closing files is not realized.
2. Files are opened exactly once for the ``backgroundclosing``
   active duration and are therefore free of race conditions between
   closing a file on a background thread and reopening it. (If the
   file were opened multiple times, there could be unflushed data
   because the original file handle hasn't been flushed/closed yet.)

``checkambig`` argument is passed to atomictempfile (valid
only for writing), and is useful only if target file is
guarded by any lock (e.g. repo.lock or repo.wlock).

To avoid file stat ambiguity forcibly, checkambig=True involves
copying ``path`` file opened in "append" mode (e.g. for
truncation), if it is owned by another. Therefore, use
combination of append mode and checkambig=True only in limited
cases (see also issue5418 and issue5584 for detail).
   br8     rr[   )r   r   r   r      N)	bufferings>   implementation error: mode %s is not valid for checkambig=TruesS   backgroundclose can only be used when a backgroundclosing context manager is active)rD   rI   r   r   r   r7   atomictempfiler   	posixfilenlinksrM   rM  
checknlinkr-   r.   rb  r   r  r   checkambigatclosingr  r  r  r  delayclosedfile)r<   r(   r=   
atomictemprh   rb   r   	auditpathmakeparentdirsrv  fnlinkrv   rp   r\   s                  r)   r?   vfs.__call__E  s+   T OOD'IIdOtDLD}$ $

1G %g
K..Z Lt|A ! "^^A.$(KKNE$qy() / 19''/+019+J8J(qy(8(8DOOA$6:^^Ay9A:a }$kk6 	  %R(B ((*i.C.C.EE ..kkG  !**B
 	_ /. ) LE%g
KLs6   .I8 I8 #I&I8 &
I50I8 5I8 84J0/J0c           	        U R                  U5        U R                  U5      n[        R                  " U5        [        R                  " [
        R                  R                  U5      U R                  5        U R                  (       a   [
        R                  " X5        g U R#                  X!5        g ! [         aH  n[        UR                  [        S5      U[        R                  " UR                   5      4-  U5      eS nAff = f)Ns   could not symlink to %r: %s)rH  rI   r   r  r   ro   r(   rv   r7   r[  symlinkr   errnor   r   
strtolocalstrerrorrd   )r<   r   r   linknameerrs        r)   r  vfs.symlink  s    

399S>x bggooh/A

3) JJs   II45H//=>?	 s   	B2 2
D<AC??Dc                    U(       a.  U R                   U/nUR                  U5        U R                  " U6 $ U R                   $ r!   )rI  extendr   )r<   r(   rH   partss       r)   rI   vfs.join  s8    YY%ELL!::u%%99r,   )rL  rM  rH  rI  r7   rK  N)TFFF)rI  r4   rH  r8   rV  r8   rS  r8   rT  r8   r.  r0  )r.  r8   )r   r4   r.  r0  r/  )rm  zMutableMapping[bytes, bool]r(   r4   r.  r8   )r[   FFFFTTr8  )r(   r4   r=   r4   r}  r8   rh   r8   rb   r8   r   r8   r~  r8   r  r8   rv  r6   r.  r   )r   r4   r   r4   r.  r0  r1  )r:  r;  r<  r=  r>  r?  rW  r   rC  r[  r9   rb  rD   ro  r?   r  rI   rF  r;   r,   r)   r  r    so    PO
KL
 "   	
   
, 
) ) 
) )0
('-' ' 
	'<    % #ss s 	s
 s s s s s s 
sj!(r,   r  z	Type[vfs]openerc                      \ rS rSrS
S jr\SS j5       rSS jr\SS j5       r\R                  SS j5       r\S 5       r
Srg	)proxyvfsi  c                    Xl         g r!   r  r<   r  s     r)   rW  proxyvfs.__init__  s    r,   c                .    U R                   R                  $ r!   )r  r7   rW   s    r)   r7   proxyvfs.createmode  s    xx"""r,   c                8    U R                   R                  X5      $ r!   )r  rD   rC   s      r)   rD   proxyvfs._auditpath  s    xx""4..r,   c                .    U R                   R                  $ r!   r  rK  rW   s    r)   rK  proxyvfs.options  s    xxr,   c                $    XR                   l        g r!   r  )r<   values     r)   rK  r    s     r,   c                .    U R                   R                  $ r!   )r  rH  rW   s    r)   rH  proxyvfs.audit  s    xx~~r,   r  Nr  r  r.  r0  )r.  r6  r/  )r.  rJ  )r  rJ  r.  r0  )r:  r;  r<  r=  rW  propertyr7   rD   rK  setterrH  rF  r;   r,   r)   r  r    s`     # #/     ^^! !  r,   r  c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)	filtervfsi  z4Wrapper vfs for filtering filenames with a function.c                :    [         R                  X5        X l        g r!   )r  rW  _filter)r<   r  filters      r)   rW  filtervfs.__init__  s    $$r,   c                L    U R                   " U R                  U5      /UQ70 UD6$ r!   )r  r  )r<   r(   r   r>   s       r)   r?   filtervfs.__call__  s$    xxT*<T<V<<r,   c                    U(       aE  U R                   R                  U R                  U R                   R                  " U/UQ76 5      5      $ U R                   R                  U5      $ r!   )r  rI   r  r   rG   s      r)   rI   filtervfs.join  sH    88==dhh.>.>t.Ng.N!OPP88==&&r,   )r  N)r  r  r  zCallable[[bytes], bytes]r.  r0  )r(   r4   r.  r   r1  	r:  r;  r<  r=  r>  rW  r?   rI   rF  r;   r,   r)   r  r    s    >
='r,   r  zType[filtervfs]filteropenerc                  :    \ rS rSrSrSS jrS	S
S jjrSS jrSrg)readonlyvfsi  z#Wrapper vfs preventing any writing.c                .    [         R                  X5        g r!   )r  rW  r  s     r)   rW  readonlyvfs.__init__
  s    $$r,   c                x    US;  a  [         R                  " [        S5      5      eU R                  " X/UQ70 UD6$ )Nrs  s   this vfs is read only)r   r  r   r  )r<   r(   r=   r   kws        r)   r?   readonlyvfs.__call__  s8    }$++a 89::xx0T0R00r,   c                <    U R                   R                  " U/UQ76 $ r!   )r  rI   rG   s      r)   rI   readonlyvfs.join  s    xx}}T,G,,r,   r;   Nr  r,  r-  r1  r  r;   r,   r)   r  r    s    -%1
-r,   r  c                      \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	\
R                  SS j5       r\
R                  SS	 j5       rS
rg)r   i  zVBase class of wrapper, which hooks closing

Do not instantiate outside the vfs layer.
c                2    [         R                  U SU5        g )N_origfh)object__setattr__)r<   fhs     r)   rW  closewrapbase.__init__  s    4B/r,   c                .    [        U R                  U5      $ r!   )r  r  r<   attrs     r)   __getattr__closewrapbase.__getattr__       t||T**r,   c                .    [        U R                  X5      $ r!   )setattrr  )r<   r  r  s      r)   r  closewrapbase.__setattr__#  s    t||T11r,   c                .    [        U R                  U5      $ r!   )delattrr  r  s     r)   __delattr__closewrapbase.__delattr__&  r  r,   c                :    U R                   R                  5         U $ r!   )r  	__enter__rW   s    r)   r  closewrapbase.__enter__)  s     r,   c                    g r!   r;   r<   exc_type	exc_valueexc_tbs       r)   __exit__closewrapbase.__exit__-  rA   r,   c                    g r!   r;   rW   s    r)   closeclosewrapbase.close1  rA   r,   r;   Nr.  r0  )r  r   r.  r   )r  r   r  r   r.  r0  )r  r   r.  r0  )r<   r   r.  r   )r:  r;  r<  r=  r>  rW  r  r  r  r  rA  rB  r  r  rF  r;   r,   r)   r   r     sT    
0+2+ 	  	 r,   c                  D   ^  \ rS rSrSrSU 4S jjrSS jrSS jrSrU =r	$ )r|  i6  z[Proxy for a file object whose close is delayed.

Do not instantiate outside the vfs layer.
c                R   > [         TU ]  U5        [        R                  U SU5        g )N_closer)superrW  r  r  )r<   r  closer	__class__s      r)   rW  delayclosedfile.__init__<  s"    4F3r,   c                N    U R                   R                  U R                  5        g r!   r  r  r  r  s       r)   r  delayclosedfile.__exit__@      4<<(r,   c                N    U R                   R                  U R                  5        g r!   r  rW   s    r)   r  delayclosedfile.closeC  r  r,   r;   r  )
r:  r;  r<  r=  r>  rW  r  r  rF  __classcell__r  s   @r)   r|  r|  6  s    
4)) )r,   r|  c                  N    \ rS rSrSrS
SS jjrSS jrSS jrSS jrSS jr	Sr
g	)r   iG  zCCoordinates background closing of file handles on multiple threads.c                H   SU l         SU l        / U l        S U l        [        R
                  nUR                  SSU5      nU(       d  g UR                  SS5      nUS:  a  X%:  a  g UR                  SS5      nUR                  SS5      nUR                  SU-  5        [        R                  R                  US	9U l        S
U l         [        U5       HM  n[        R                  " U R                  SS9n	U R                  R!                  U	5        U	R#                  5         MO     g )NFs   workers   backgroundcloses   backgroundcloseminfilecountr   s   backgroundclosemaxqueues   backgroundclosethreadcounts0   starting %d threads for background file closing
)maxsizeTbackgroundcloser)targetr   )_running_entered_threads_threadexceptionr   	iswindows
configbool	configintdebugqueueQueue_queueranger  Thread_workerrl   start)
r<   r   r  defaultenabledenabledminfilecountmaxqueuethreadcountir	  s
             r)   rW  backgroundfilecloser.__init__J  s    $ "++--	+=~N
 ||I/MN 1!=<<	+EFll9.KL
@;N	
 nn**8*<{#A  ;MNAMM  #GGI $r,   c                    SU l         U $ r5  )r  rW   s    r)   r  backgroundfilecloser.__enter__p  s    r,   c                X    SU l         U R                   H  nUR                  5         M     g )NF)r  r  rI   )r<   r  r  r  r	  s        r)   r  backgroundfilecloser.__exit__t  s"     AFFH r,   c                     U R                   R                  SSS9n UR                  5         M.  ! [         a  nX l         SnANSnAff = f! [
        R                  R                   a    U R                  (       d   g NRf = f)zMain routine for worker thread.Tg?blocktimeoutN)	r  getr  r   r  r   r  Emptyr  r<   r  es      r)   r  backgroundfilecloser._worker|  sw    [[__4_?.HHJ  ! .,-)). >>'' }} %s1   A 0 
A
A A A

A /B Bc                *   U R                   (       d  [        R                  " [        S5      5      eU R                  (       a  U R                  nSU l        UeU R
                  (       d  UR                  5         gU R                  R                  USSS9  g)zSchedule a file for closing.s1   can only call close() when context manager activeNTr
  )	r  r   r  r   r  r  r  r  putr  s      r)   r  backgroundfilecloser.close  sq    }}++FG    %%A$(D!G }}HHJ$5r,   )r  r  r  r  r  Nr7  )r   r9  r  r6   r.  r0  )r<   r   r.  r   r  )r:  r;  r<  r=  r>  rW  r  r  r  r  rF  r;   r,   r)   r   r   G  s    M$L 6r,   c                  N   ^  \ rS rSrSrSU 4S jjrSS jrSS jrSS jrSr	U =r
$ )	r{  i  a  Proxy for a file object, to avoid ambiguity of file stat

See also util.filestat for detail about "ambiguity of file stat".

This proxy is useful only if the target file is guarded by any
lock (e.g. repo.lock or repo.wlock)

Do not instantiate outside the vfs layer.
c                   > [         TU ]  U5        [        R                  U S[        R
                  R                  UR                  5      5        g )N_oldstat)r  rW  r  r  r   r"   r#   r   )r<   r  r  s     r)   rW  checkambigatclosing.__init__  s5    4T]]-C-CBGG-LMr,   c                    U R                   nUR                  (       a!  [        U R                  R                  U5        g g r!   )r  r   r/   r  r   )r<   r'   s     r)   _checkambigcheckambigatclosing._checkambig  s+    --<<))73 r,   c                \    U R                   R                  XU5        U R                  5         g r!   )r  r  r  r  s       r)   r  checkambigatclosing.__exit__  s"    h6:r,   c                X    U R                   R                  5         U R                  5         g r!   )r  r  r  rW   s    r)   r  checkambigatclosing.close  s    r,   r;   r  )r:  r;  r<  r=  r>  rW  r  r  r  rF  r  r  s   @r)   r{  r{    s"    N4
 r,   r{  )r(   r4   r'   zutil.filestatr.  r0  )5
__future__r   rA  rD  ro   r   r   r  typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   i18nr    r   r   r   r   r   TYPE_CHECKINGr   uimodr   r   r   r  
_OnErrorFnr/   ABCr1   r  r  r?  r  r  r  r  r   r|  r   r{  r;   r,   r)   <module>r(     s*   # 
  	       "   
 % (> /GO9+x'778J&^#'' ^Bh+ hV 	 {CGG 0'+ '$ !*o )-( - CGG >)m )"Y6 Y6x- r,   