a +b5\@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZddlmZmZmZmZedZejjZejjZejjZz ejZWneydd ZYn0ej Z ej!Z!ej"Z"ej#Z#d Z$e%dZ%e%e%ej&s,dmd dZ'neZ'ddZ(ddZ)ddZ*ddZ+ddZ,ddZ-ddZ.dnddZ/dd Z0d!d"Z1d#d$Z2d%d&Z3d'd(Z4d)d*Z5d+d,Z6d-d.Z7d/d0Z8d1d2Z9d3d4Z:d5d6Z;eje;Z?ej@rd7d6Z;ejd8d9Z?ejAd:kr>eBgd;dd6Z;eje;Z?d?d Z0d@d"Z1daEdAdBZFdCdDZGdEdFZHdGdHZIdIdJZJdKdLZKe jLe jMhZNdMdNZOdOdPZPdodQdRZQdpdSdTZRdUdVZSdWdXZTdYdZZUd[d\ZVdqd]d^ZWd_d`ZXGdadbdbeYZZdcddZ[dedfZ\dgdhZ]didjZ^dkdlZ_dS)r)absolute_importN)_)getattropen)encodingerrorpolicypycompatosutilcCsttjd||fdS)Ns!hardlinks not supported: %s to %s)OSErrorerrnoEINVAL)srcdstr5/usr/lib64/python3.9/site-packages/mercurial/posix.pyoslink0srFrcCs(t|||d}d|vr$|dtj|S)N)mode bufferingar)rseekosSEEK_END)namerrfprrr posixfileAsrcCsR|dd}t|dkr d|fS|dd}|r>||dfS|dd|dfS)aSame as posixpath.split, but faster >>> import posixpath >>> for f in [b'/absolute/path/to/file', ... b'relative/path/to/file', ... b'file_alone', ... b'path/to/directory/', ... b'/multiple/path//separators', ... b'/file_at_root', ... b'///multiple_leading_separators_at_root', ... b'']: ... assert split(f) == posixpath.split(f), f /rr)rsplitlenrstrip)pZhtZnhrrrsplitPs   r%cCsdS)z@return true if it is safe to hold open file handles to hardlinksTrrrrr openhardlinksgsr&cCs t|jS)z-return number of hardlinks for the given file)rlstatst_nlinkrrrrnlinkslsr*cCs\|dd}tjdkr0|ddkrX|dd}n(|drX|drXd |vrX|dd}|S) zc Cst|}|j}|rt|st|d}|}Wdn1sF0Yt|zt||WnFt yt|d}| |Wdn1s0YYn0dSt|rt |}t|t|d}| |Wdn1s0Ydt @}|d@}|j dkrt|t|krt|d}|}Wdn1s`0Yt|t|d}| |Wdn1s0Y|r|st|||d@d?t @Bn|s|rt||d@dS)Nsrbswbr;ri$)rr'r<statS_ISLNKrreadunlinksymlinkr writereadlinkumaskr(boolchmod)r=lxstsrdataZsxrrrsetflagss<   &  .   (  ( *   rPc Cszt|jd@}WnLty`}z4|jtjkr2|}|durDt}|dM}WYd}~n d}~00|}|rt|tjO}t ||dS)zCopy the file mode from the file at path src to dst. If src doesn't exist, we're using mode instead. If mode is None, we're using umask.Nr?) rr'r<r r ENOENTrHrAS_IWUSRrJ)rrrZenforcewritabler<instZnew_moderrrcopymodes  rUc CszftjtjBtjB}tj|d}tj|d}tj|d}tj|sz0t|tj|rpt ||n t ||Wnt t fyYn0tj |rtj|d}tj|d}zt|j }Wn4t y}z|jtjkrWYd}~nd}~00||@dkrzt|j }WnPt yr}z6|jtjkrDt|dt|j }WYd}~n d}~00||@dkrWd St|t||} n|} d}tj| d d \} } zt| t| j }||@dkr|jtjkrWYd}~W|dur|WqWYd}~n d}~00W|dur|n|dur|0WqtyYd StyP}z2|jtjkr:tj|r:t|WYd}~d Sd}~00qdS) z?check whether the given path is on a symlink-capable filesystemrVrWs checklinkTNz checklink-rYs hg-checklink-schecklink-targetrXrF)rr_r`islinkrdtempfileZmktempr fsdecodefsencodeZ namedtempfilebasenamerrrercr ZEACCESrErDrfr ZEEXISTAttributeErrorZEIOra) r_rg checklinkrjrfdtargetfullpathrTrrrrs$sp            rscCsdS)zCheck that the base-relative path is a valid filename on this platform. Returns None if the path is ok, or a UI string describing the problem.Nrr_rrrcheckosfilenamelsrxcCsttddd|S)zGet the filesystem mount point from a directory (best-effort) Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. getfsmountpointcSsdSNrrLrrrwr z!getfsmountpoint..rr dirpathrrrryrsrycCsttddd|S)zGet the filesystem type name from a directory (best-effort) Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. getfstypecSsdSrzrr{rrrr|r zgetfstype..r}r~rrrrzsrcCsttdS)N)rZ strtolocalgetpassrrrr get_passwordsrcCsdSrzr)rtrrr setbinarysrcCs|SrzrrwrrrpconvertsrcCs|Srzrrwrrr localpathsrcCstj||S)zwReturns whether path1 and path2 refer to the same file. This is only guaranteed to work for files, not directories.)rr_samefile)fpath1fpath2rrrrsrcCs t|}t|}|j|jkS)zyReturns whether fpath1 and fpath2 are on the same device. This is only guaranteed to work for files, not directories.)rr'st_dev)rrZst1Zst2rrr samedevices  rcCs|Srz)lowerrwrrrnormcasesrcCs,z t|WSty&t|YS0dS)a Normalize a filename for OS X-compatible comparison: - escape-encode invalid characters - decompose to NFD - lowercase - omit ignored characters [200c-200f, 202a-202e, 206a-206f,feff] >>> normcase(b'UPPER') 'upper' >>> normcase(b'Caf\xc3\xa9') 'cafe\xcc\x81' >>> normcase(b'\xc3\x89') 'e\xcc\x81' >>> normcase(b'\xb8\xca\xc3\xca\xbe\xc8.JPG') # issue3918 '%b8%ca%c3\xca\xbe%c8.jpg' N)rZ asciilowerUnicodeDecodeErrornormcasefallbackrwrrrrs  c Csz|d}Wntyd}d}t|}||krzt||}|t|7}Wn2tydt|||d}|d7}Yn0||7}q,|d}Yn0td| d}t |S)Nzutf-8r rs%%%02XrZNFD) decoderr"rZ getutf8char ValueErrorord unicodedata normalizerencodeZhfsignoreclean)r_urNposrKcencrrrrs"    rscygwin)s/usr/bins/usr/libs /cygdriveT)reversecCst|}|dks|dtjkr(t|StD]P}||s.findexistingsplan9s/binsPATHr N) r r0rrr_r`renvirongetr%Z ospathsep)Zcommandrr_rrrrfindexe7s    rcCsdSrzrrrrrsetsignalhandlerRsrc cs|tj}tj}|D]f}z||}||jtvr0d}Wn<tyn}z$|jtjtj fvrVd}WYd}~n d}~00|VqdS)zqStat each file in files. Yield each stat, or None if a file does not exist or has a type we don't care about.N) rr'rAS_IFMTr< _wantedkindsr r rRENOTDIR)filesr'ZgetkindZnfrMerrrrr statfilesYsrcCsttS)zreturn name of current user)r rprgetuserrrrrrjsrcCsF|durt}ztt|dWSty@d|YS0dS)ziReturn the name of the user with the given uid. If uid is None, return the name of the current user.Nrs%d)rrr rppwdgetpwuidKeyError)uidrrrusernameos  rcCsH|durt}ztt|dWStyBt|YS0dS)zkReturn the name of the group with the given gid. If gid is None, return the name of the current group.Nr)rgetgidr rpgrpgetgrgidrZbytestr)gidrrr groupname|s  rcCs$t|}ttjtt|jS)zkReturn the list of members of the group with the given name, KeyError if the group does not exist. )r roZrapplyrplistrgetgrnamgr_memr)rrr groupmemberss rcCs ttjttddB|d|S)NZP_DETACHr)rspawnvpP_NOWAITr)r9rrr spawndetachedsrcCstjddS)Nr)sysargvrrrrgethgcmdsrcCst|dSrz)rrb)r_Z notindexedrrrmakedirsrcCsdSrzr)keyrZscoperrr lookupregsrcCsdS)zHide current shell window. Used to hide the window opened when starting asynchronous child process under Windows, unneeded on other systems. Nrrrrr hidewindowsrc@s2eZdZddZddZejZddZddZd S) cachestatcCst||_dSrz)rrA)selfr_rrr__init__szcachestat.__init__cCs t|jjSrz)rIrAst_ino)rrrr cacheableszcachestat.cacheablecCsz|jj|jjko|jj|jjko|jj|jjko|jj|jjko|jj|jjko|jj|jjko|jj|jjko|jtj|jtjko|jtj |jtj kWSt yYdS0dSr) rAr<rrr(rst_gidst_sizeST_MTIMEST_CTIMErrrotherrrr__eq__s( zcachestat.__eq__cCs ||k Srzrrrrr__ne__szcachestat.__ne__N) __name__ __module__ __qualname__rrobject__hash__rrrrrrrs rcCs|ot|jS)z(check whether a stat result is a symlink)rArBr<rrrr statislinksrcCs|o|jd@dkS)z1check whether a stat result is an executable filer;r)r<rrrr statisexecsrc Cszbzt|||}Wq`Wqtjy\}z*|jdtjkrFWYd}~qWYd}~qd}~00qWntyztYn0ttt t |gS)zblock until something happens on any file descriptor This is a generic helper that will check for any activity (read, write. exception) and return the list of touched files. In unsupported cases, it will raise a NotImplementedErrorrN) selectrr9r ZEINTRrNotImplementedErrorsortedrsetsum)ZfdsresrTrrrpolls   rc Cst|tj}|tjO}t|tj|}zXg}z|}|s@Wqf||Wq.tybYqfYq.0q.d|Wt|tj|St|tj|0dS)z$Read all available data from a pipe.r N) fcntlZF_GETFLr O_NONBLOCKZF_SETFLrCappendrcr`)pipeflagsZoldflagschunksrNrrrreadpipes     rc Csptj|\}}d}zF|r2tdtj}t||||rJt|W|rlt|n|rjt|0dS)z1Bind the UNIX domain socket to the specified pathN.) rr_r%r O_DIRECTORYchdirZbindfchdirre)Zsockr_dirnamerqZbakwdfdrrrbindunixsockets    r)rr)NF)N)N)NN)`Z __future__rr rrrrrrrrArrnrZi18nrr rrrrrr Z importmodr r_normpathsamestatabspathlinkrrrrGrDrf removedirsZ expandglobsrHZispy3rr%r&r*r3r:r>rPrUrlrsrxryrrrrrrrrZ normcasespecsrZ normcasespecrZisdarwinr0rrrrr5rrrrrS_IFREGS_IFLNKrrrrrrrrrrrrrrrrrrrrrrs          , SH         "