^cbpddlZddlZddlZddlZddlZddlmZddlmZm Z m Z ddl m Z m Z mZmZmZdZGddZGd d eZeZGd d eZGd deeZeZGddeZGddZGddeZGddZGddeZdS)N)_)delattrgetattrsetattr)encodingerrorpathutilpycompatutilcfd}|s3tjtj|dSdS)zAvoid file stat ambiguity forcibly This function causes copying ``path`` file, if it is owned by another (see issue5418 and issue5584 for detail). ctj}| p|SN)r filestatfrompathisambig avoidambig)newstatoldstatpaths //usr/lib/python3/dist-packages/mercurial/vfs.py checkandavoidz"_avoidambig..checkandavoid$sB-((..??7+++Pw/A/A$/P/PPN)r rename mktempcopy)rrrs`` r _avoidambigrsoQQQQQQ =?? DOD))4000  rceZdZdZdZdZd;dZdZdZdZ d;d Z e j d Z d Zd;d ZddZdZd>dZd>dZd>dZd>dZdZdZdZd>dZd>d Z d>d!Z!d?d#Z"d@d$Z#d%Z$d>d&Z%dAd)Z&dBd*Z'd+Z(dd.Z+d>d/Z,dCd0Z-d1Z.d>d2Z/d>d3Z0d>d4Z1dDd5Z2d@d6Z3d@d7Z4e5j6dEd9Z7d:Z8dS)F abstractvfsz+Abstract base class; cannot be instantiated/cZtdtt|z)z7Prevent instantiation; don't call this from subclasses.attempted instantiating NotImplementedErrorstrtype)selfargskwargss r__init__zabstractvfs.__init__;s"!">$T>22 2     D  s  &&c|jS)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 ropenzabstractvfs.openXs }rcv||d5}|cdddS#1swxYwYdS)Nr*)r8)r&rfps rr8zabstractvfs.readbs T$   "7799                  s .22cx|||5}|cdddS#1swxYwYdS)Nr=)r>)r&rr-rDs rr>zabstractvfs.readlinesfs T$T " " " "b<<>> " " " " " " " " " " " " " " " " " "s /33Fc x||dfd|i|5}||cdddS#1swxYwYdS)Nwbbackgroundclosewrite)r&rdatarHr(rDs rrJzabstractvfs.writejs T$ I I I& I I "R88D>> " " " " " " " " " " " " " " " " " " /33rGc|||||5}||cdddS#1swxYwYdS)N)r- notindexed) writelines)r&rrKr-rNrDs rrOzabstractvfs.writelinesns T$Tj 9 9 9 'R==&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's 155cx||d5}||cdddS#1swxYwYdS)NsabrI)r&rrKrDs rappendzabstractvfs.appendrs T$   ""88D>> " " " " " " " " " " " " " " " " " "rLc@tj|S)zreturn base element of a path (as os.path.basename would do) This exists to allow handling of strange encoding if needed.)osrbasenamer:s rrTzabstractvfs.basenamevsw%%%rcRtj|||Sr)rSchmodr6r1s rrVzabstractvfs.chmod|sx $...rc@tj|S)zreturn dirname element of a path (as os.path.dirname would do) This exists to allow handling of strange encoding if needed.)rSrdirnamer:s rrXzabstractvfs.dirnameswt$$$rNcftj||Sr)rSrexistsr6r:s rrZzabstractvfs.exists w~~diioo...rc*tj|Sr)r fstat)r&rDs rr]zabstractvfs.fstatsz"~~rcftj||Sr)rSrisdirr6r:s rr_zabstractvfs.isdirs w}}TYYt__---rcftj||Sr)rSrisfiler6r:s rrazabstractvfs.isfiler[rcftj||Sr)rSrislinkr6r:s rrczabstractvfs.islinkr[rc ||}n#t$rYdSwxYw|j}tj|ptj|S)zhreturn whether path is a regular file or a symlink Unlike isfile, this doesn't follow symlinks.F)lstatOSErrorst_modestatS_ISREGS_ISLNK)r&rstr-s r isfileorlinkzabstractvfs.isfileorlinksb D!!BB   55 z|D!!7T\$%7%77s  &&cd}t|D]@\}}tj|s||jr|}A|dkr ||d}d|D}|j|S)Nrcg|]}||Sro).0ps r z%abstractvfs._join..s'''qQ''''r) enumeraterSrisabs startswith_dir_sepr6)r&pathsroot_idxidxrqs r_joinzabstractvfs._joins&&  FCw}}Q 1<< #>#>  q==())$E''E'''}!!%(((rc|j|S)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.)rz)r&rws rreljoinzabstractvfs.reljoins tz5!!rc@tj|S)zsplit top-most element of a path (as os.path.split would do) This exists to allow handling of strange encoding if needed.)rSrsplitr:s rr~zabstractvfs.splitsw}}T"""rcftj||Sr)rSrlexistsr6r:s rrzabstractvfs.lexistss wtyy///rcPtj||Sr)rSrer6r:s rrezabstractvfs.lstatx $(((rcPtj||Sr)rSlistdirr6r:s rrzabstractvfs.listdirsz$))D//***rTcRtj|||Sr)r makedirr6)r&rrNs rrzabstractvfs.makedirs|DIIdOOZ888rcRtj|||Sr)r makedirsr6r1s rrzabstractvfs.makedirss}TYYt__d333rcRtj|||Sr)r makelockr6)r&infors rrzabstractvfs.makelocks}T499T??333rcPtj||Sr)rSmkdirr6r:s rrzabstractvfs.mkdirrrrtmpctj||||\}}tj|\}}|r"|t j||fS||fS)N)suffixprefixdir)r mkstempr6r r~rSr)r&rrrfdnamednamefnames rrzabstractvfs.mkstempsp#&diinn   Dz$'' u  rw||C/// /u9 rcTtj||||Sr)r rr6)r&rrhskips rreaddirzabstractvfs.readdirs |DIIdOOT4888rcPtj||Sr)r readlockr6r:s rrzabstractvfs.readlock}TYYt__---rcN||d||}||}|otj|}|r.|jr'tj||}t|||Stj||S)aRename 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). w)r2r6r rrrhrr)r&srcdst checkambigsrcpathdstpathrrets rrzabstractvfs.renames T"""))C..))C..@!7!7!@!@  w| +gw//C  ) ) )J{7G,,,rcPtj||Sr)r readlinkr6r:s rrzabstractvfs.readlinkrrcPtj||S)z7Remove a leaf directory and all empty intermediate ones)r removedirsr6r:s rrzabstractvfs.removedirsstyy///rcPtj||S)zRemove an empty directory.)rSrmdirr6r:s rrzabstractvfs.rmdirsx $(((rcf|rd}nd}tj||||S)zqRemove a directory tree recursively If ``forcibly``, this tries to remove READ-ONLY files, too. c|tjurtj|}|jtjzdkrtj|tj|jtjztj|dS)Nr)rSremoverhrgS_IWRITErVS_IMODE)functionrexcinfoss ronerrorz#abstractvfs.rmtree..onerrorsl29,,GDMMI -!33t|AI66FGGG $rN) ignore_errorsr)shutilrmtreer6)r&rrforciblyrs rrzabstractvfs.rmtreesQ      G} IIdOO='    rcTtj||||Sr)r setflagsr6)r&rlxs rrzabstractvfs.setflagss }TYYt__a333rcPtj||Sr)rSrhr6r:s rrhzabstractvfs.statswtyy'''rcPtj||Sr)r unlinkr6r:s rrzabstractvfs.unlinks{499T??+++rcTtj||dS)z7Attempt to remove a file, ignoring missing file errors.N)r tryunlinkr6r:s rrzabstractvfs.tryunlinks" tyy'''''rcVtj||||S)N) ignoremissingr)r unlinkpathr6)r&rrrs rrzabstractvfs.unlinkpath s, IIdOO=    rcRtj|||Sr)rSutimer6)r&rts rrzabstractvfs.utime%sx $+++rc#.Ktj|d}t t j|}tj|||D]\}}}||d||fVdS)a/Yield (dirpath, dirs, files) tuple for each directories 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)rSrnormpathr6lenr normasprefixwalk)r&rrroot prefixlendirpathdirsfiless rrzabstractvfs.walk(sw $00-d3344 $&GDIIdOOW$M$M$M 5 5 GT59::&e4 4 4 4 4 5 5rc#KttjtjsdVdSt |d|}t |ddr!t jtdt||5} ||_ |Vd|_ n #d|_ wxYw ddddS#1swxYwYdS)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. Nvfs_backgroundfileclosers-can only have 1 active background file closer) expectedcount) isinstance threadingcurrent_thread _MainThreadrr Abortrbackgroundfilecloserr)r&uirrbfcs rbackgroundclosingzabstractvfs.backgroundclosing8sF  $ & &  !    EEE FdE4(( 3/ 6 6 +BCC ""M B B B c ) ))))                  s*B7 BB7 B&&B77B;>B;cdS)z1generic hook point to lets fncache steer its stewNror:s r register_filezabstractvfs.register_fileZsr)r*)F)rGFrNT)NN)rrN)NNN)NFF)NFTr)9__name__ __module__ __qualname____doc__rvr)r.r2r6r;r?r propertycacherBr8r>rJrOrQrTrVrXrZr]r_rarcrlrzr|r~rrerrrrrrrrrrrrrrrhrrrrr contextlibcontextmanagerrrrorrrr0s55HPPP"""""""""" """"""""''''"""&&& ///%%% ////....//////// 8 8 8 8)))"""### 0000))))++++99994444444))))9999...----,...0000))))    .444((((,,,,((((    ,,,,5555 B@@@@@rrceZdZdZ ddZejdZejdZdZ dZ dd Z d Z d Z d S)rakOperate 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. TFc|rtj|}|rtj|}||_||_|r!tj|j||_ n dd|_ d|_ d|_ i|_ dS)N)cachedcdSrro)rr-s rzvfs.__init__..zsrr) r expandpathrSrrealpathbase_auditr pathauditoraudit createmode _trustnlinkoptions)r&rr cacheauditedrrs rr)z vfs.__init__is  )?4((D  *7##D))D   6!-di MMMDJJ555DJ rc4tj|jSr)r checklinkrrAs r _cansymlinkzvfs._cansymlink~di(((rc4tj|jSr)r checkexecrrAs r_chmodz vfs._chmodrrc`|j|jsdStj||jdzdS)Ni)rrrSrV)r&rs r _fixfilemodezvfs._fixfilemodes5 ? "$+ " F t./////rc`|jrtj|r?||jr%tj||j}tj|}|rtj d||fz| ||dSdS)Ns%s: %rr=) rrSrrtrurrelpathr checkosfilenamer rr)r&rr-rs rr2zvfs._auditpaths ; (w}}T"" 8tty'A'A 8wtTY77$T**A 9k)q$i"7888 JJt$J ' ' ' ' '  ( (rrc |r|||||} d|vr|dz }d} |dvrJtj| \} } | r0|r:|rtj| |j|tj| ||j|S d|vrtj| d} nHtj| 5tj | } | dkrd} d d d n #1swxYwYn/#t$r"d} |rtj| |j|YnwxYw| dkrZ|j | dkptj | |_ | dks|j s'tj tj| | tj| |} | dkr|| |r7|dvr$t!jt%d |zt'| } |rht)t+jt*jr=|js!t!jt%d t3| |j} | S) aOpen ``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). brrr*)rrrrNs>implementation error: mode %s is not valid for checkambig=TruesSbackgroundclose can only be used when a backgroundclosing context manager is active)r2r6r r~rratomictempfiler posixfilenlinksr9r checknlinkrrrr rrcheckambigatclosingrrrrrdelayclosedfile)r&rr- atomictemprNrHr auditpathmakeparentdirsfnlinkrXrTrDs rr.z vfs.__call__sR  ( OOD$ ' ' ' IIdOO t   DLD } $ $ $ 1 GX ;%L gt KKK.4ZLt|| A !"^A..**$(KNNE$qyy()***************)LLLE%L gt KKKL199'/+019+J8J8J(qyy(8y DOA$6$6::: ^At $ $ A::   a  )}$$k6 %R((B  z  $ & &  !    . kG!*B  s6/C9C-! C9-C11C94C15C99)D%$D%c ||||}tj|tjt j||j|j ri t j ||dS#t$rD}t|j td|tj|jfz|d}~wwxYw|||dS)Nscould not symlink to %r: %s)rr6r rrrSrrXrrsymlinkrferrnorr strtolocalstrerrorrJ)r&rrlinknameerrs rrz vfs.symlink s 399S>> x    bgooh//AAA   !  3)))))   I455H/ ==>?   JJsC s>B C#?CC#cd|r(|j|g}|||j|S|jSr)rextendrz)r&rr5partss rr6zvfs.joins?  Y%E LL ! ! !4:u% %9 rN)TFFF)rFFFFTT)rrrrr)r rrrrr2r.rr6rorrrr^s , ))) )))000 (((rrrrh!!!(rrcPeZdZdZdZedZejdZdS)proxyvfsc||_dSr)rr&rs rr)zproxyvfs.__init__*s rc8|j||Sr)rr2r1s rr2zproxyvfs._auditpath-sx""4...rc|jjSrrrrAs rrzproxyvfs.options0s xrc||j_dSrr')r&values rrzproxyvfs.options4s rN)rrrr)r2propertyrsetterrorrr"r")sj///  X  ^!!^!!!rr"c$eZdZdZdZdZdZdS) filtervfsz4Wrapper vfs for filtering filenames with a function.cJt||||_dSr)r"r)_filter)r&rfilters rr)zfiltervfs.__init__<s#$$$$ rcJ|j||g|Ri|Sr)rr/)r&rr'r(s rr.zfiltervfs.__call__@s0tx T**|j||jj|g|RS|j|Sr)rr6r/r|r4s rr6zfiltervfs.joinCsV  '8==.>dh.>t.Ng.N.N.N!O!OPP P8==&& &rNrrrrr)r.r6rorrr-r-9sG>>==='''''rr-c&eZdZdZdZddZdZdS) readonlyvfsz#Wrapper vfs preventing any writing.c<t||dSr)r"r)r$s rr)zreadonlyvfs.__init__Ps$$$$$$rrcp|dvr!tjtd|j||g|Ri|S)Nr sthis vfs is read only)r rrr)r&rr-r'kws rr.zreadonlyvfs.__call__SsJ } $ $+a 899:: :txd0T000R000rc(|jj|g|RSr)rr6r4s rr6zreadonlyvfs.joinXstx}T,G,,,,rN)rr3rorrr5r5MsL--%%%1111 -----rr5c<eZdZdZdZdZdZdZdZdZ dZ d S) closewrapbasezaBase class of wrapper, which hooks closing Do not instantiate outside of the vfs layer. c>t|d|dS)N_origfh)object __setattr__)r&fhs rr)zclosewrapbase.__init__bs 4B/////rc,t|j|Sr)rr=r&attrs r __getattr__zclosewrapbase.__getattr__et|T***rc.t|j||Sr)rr=)r&rCr)s rr?zclosewrapbase.__setattr__hst|T5111rc,t|j|Sr)rr=rBs r __delattr__zclosewrapbase.__delattr__krErc8|j|Sr)r= __enter__rAs rrJzclosewrapbase.__enter__ns     rcZtdtt|zNr!r"r&exc_type exc_valueexc_tbs r__exit__zclosewrapbase.__exit__r"!"r?)r&r@closer __class__s rr)zdelayclosedfile.__init__s? ot$$--b1114F33333rcD|j|jdSrrWrTr=rMs rrQzdelayclosedfile.__exit__  4<(((((rcD|j|jdSrr\rAs rrTzdelayclosedfile.closer]r)rrrrr)rQrT __classcell__rZs@rrrys` 44444))))))))))rrc2eZdZdZd dZdZdZdZdZdS) rzCCoordinates background closing of file handles on multiple threads.rcjd|_d|_g|_d|_tj}|dd|}|sdS|dd}|dkr||krdS|dd}|dd}|d|ztj | |_ d |_t|D]K}tj|jd } |j| | LdS) NFsworkersbackgroundclosesbackgroundcloseminfilecountrsbackgroundclosemaxqueuesbackgroundclosethreadcounts0starting %d threads for background file closing )maxsizeTbackgroundcloser)targetr)_running_entered_threads_threadexceptionr iswindows configbool configintdebugqueueQueue_queuerangerThread_workerrQstart) r&rrdefaultenabledenabled minfilecountmaxqueue threadcountirs rr)zbackgroundfilecloser.__init__sE   $"+-- +=~NN  F ||I/MNN  1  !=!= F<< +EFFll9.KLL   @; N   n**8*<<  {##  A  ;MNNNA M  # # # GGIIII  rcd|_|Sr)rgrAs rrJzbackgroundfilecloser.__enter__s  rcPd|_|jD]}|dS)NF)rfrhr6)r&rNrOrPrs rrQzbackgroundfilecloser.__exit__s5   A FFHHHH  rc |jdd} |n#t$r}||_Yd}~nd}~wwxYwn$#t jj$r |jsYdSYnwxYww)zMain routine for worker thread.Tg?blocktimeoutN) rpgetrT Exceptionrir rnEmptyrfr&r@es rrszbackgroundfilecloser._workers  [__4_??.HHJJJJ ...,-D)))))).>'   }EE  s6A5A AA A AAA54A5c|js!tjtd|jr|j}d|_||js|dS|j|dddS)zSchedule a file for closing.s1can only call close() when context manager activeNTr~) rgr rrrirfrTrpputrs rrTzbackgroundfilecloser.closes} +FGG    %A$(D !G}  HHJJJ F $55555rNr) rrrrr)rJrQrsrTrorrrrskMM$$$$L 66666rrc4eZdZdZfdZdZdZdZxZS)ra"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 of the vfs layer. ctt||t|dt j|jdS)N_oldstat) rXrr)r>r?r rrr)r&r@rZs rr)zcheckambigatclosing.__init__sR !4((11"5554T]-C-CBG-L-LMMMMMrcZ|j}|jrt|jj|dSdSr)rrhrr=r)r&rs r _checkambigzcheckambigatclosing._checkambigs8- < 4  )7 3 3 3 3 3 4 4rcf|j||||dSr)r=rQrrMs rrQzcheckambigatclosing.__exit__s4 h 6::: rc`|j|dSr)r=rTrrAs rrTzcheckambigatclosing.closes.  r) rrrrr)rrQrTr_r`s@rrrstNNNNN444 rr)rrSrrhri18nrr rrrrr r r rrropenerr"r- filteropenerr5r;rrrrorrrs  &k@k@k@k@k@k@k@k@\ EEEEE+EEEP  ! ! ! ! !{ ! ! ! '''''+'''"  - - - - -( - - -PPPPPPPP:)))))m)))"Y6Y6Y6Y6Y6Y6Y6Y6x-r