o ]Lb5\@s ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZddlmZmZmZmZedZejjZejjZejjZzejZWn eysdd ZYnwej Z ej!Z!ej"Z"ej#Z#d Z$e%dZ%e%e%ej&sdmd 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:kreBgd;dd6Z;eje;Z?d?d Z0d@d"Z1daEdAdBZFdCdDZGdEdFZHdGdHZIdIdJZJdKdLZKe jLe jMhZNdMdNZOdOdPZPdodQdRZQdodSdTZRdUdVZSdWdXZTdYdZZUd[d\ZVdpd]d^ZWd_d`ZXGdadbdbeYZZdcddZ[dedfZ\dgdhZ]didjZ^dkdlZ_dS)q)absolute_importN)_)getattropen)encodingerrorpolicypycompatosutilcCsttjd||f)Ns!hardlinks not supported: %s to %s)OSErrorerrnoEINVAL)srcdstr1/usr/lib/python3/dist-packages/mercurial/posix.pyoslink0srFrcCs(t|||d}d|vr|dtj|S)N)mode bufferingar)rseekosSEEK_END)namerrfprrr posixfileAsrcCsR|dd}t|dkrd|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)phtnhrrrsplitPs   r'cCdS)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_nlinkrrrrnlinksls r-cCs^|dd}tjdkr|ddkr|dd}|S|dr-|dr-d |vr-|dd}|S) zwz!getfsmountpoint..rr dirpathrrrrrrcCr)zGet the filesystem type name from a directory (best-effort) Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. getfstypecSrrrrrrrrrzgetfstype..rrrrrrzrrcCsttdS)N)r strtolocalgetpassrrrr get_passwordrcCrrr)rrrr setbinaryrcC|SrrrrrrpconvertrrcCrrrrrrr localpathrrcCstj||S)zwReturns whether path1 and path2 refer to the same file. This is only guaranteed to work for files, not directories.)rrisamefile)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)rrst1st2rrr samedevices   rcCs|Sr)lowerrrrrnormcasesrcCs(zt|WStyt|YSw)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' )r asciilowerUnicodeDecodeErrornormcasefallbackrrrrrs    c Csz|d}WnJtyQd}d}t|}||krJzt||}|t|7}WntyAdt|||d}|d7}Ynw||7}||ks|d}Ynwtd| d}t |S)Nzutf-8r rs%%%02XrNFD) decoderr"r getutf8char ValueErrorord unicodedata normalizerencodehfsignoreclean)riurUposrRcencrrrrs(      rscygwin)s/usr/bins/usr/libs /cygdriveT)reversecCst|}|dks|dtjkrt|StD](}||sqt|}||kr*|S||tjkr>|t||dSqt|S)Nr)r"r ossepruppercygwinmountpointsr4)ripathlenmpmplenrrrrs   cCr(NFrrrrrr}rcCr(rrrrrrrrcCsFtjdkr d|Stdurtdja|rt|s|Sd|ddS)Nr/s"%s"s[^a-zA-Z0-9._/+-]s'%s'r1s'\'')r r3_needsshellquoterecompilesearchreplacerUrrrr;s   r;cCstj|ddS)z7Parse a command string in POSIX shell way (best-effort)T)posix)r shlexsplitrrrr shellsplit"rc CsRtjdkrdSz t|dWdSty(}z |jtjkWYd}~Sd}~ww)z5return False if pid dead, True if running or not surer/TrN)r r3rkillr r ESRCH)pidr]rrrtestpid's  rcCs|jtkS)z;Return True if the stat object st is from the current user.)st_uidrgetuidrTrrrisowner2rrcCstjdkr|Sdd}tj|vr||Stjdkr"|tjd|Stjdd tj D]}|tj||}|dur@|Sq-dS) zFind executable for command searching like which does. If command is a basename then PATH is searched for command. PATH isn't searched if command is an absolute or relative path. If command isn't found None is returned.r/cSs$ tj|rt|tjr|SdSr)rriisfileaccessX_OK) executablerrr findexisting?szfindexe..findexistingsplan9s/binsPATHr N) r r3rrrirjrenvirongetr' ospathsep)commandrrirrrrfindexe7s   rcCrrrrrrrsetsignalhandlerRrrc cs~tj}tj}|D]3}z||}||jtvrd}Wnty8}z|jtjtj fvr,d}WYd}~nd}~ww|Vq dS)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*rHS_IFMTrC _wantedkindsr r rZENOTDIR)filesr*getkindnfrTerrrrr statfilesYs"rcCsttS)zreturn name of current user)r rrgetuserrrrrrjrrcCsB|durt}z tt|dWSty d|YSw)ziReturn the name of the user with the given uid. If uid is None, return the name of the current user.Nrs%d)rrr rpwdgetpwuidKeyError)uidrrrusernameos  rcCsD|durt}z tt|dWSty!t|YSw)zkReturn the name of the group with the given gid. If gid is None, return the name of the current group.Nr)rgetgidr rgrpgetgrgidrbytestr)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 rrapplyrlistrgetgrnamgr_memr,rrr groupmemberss rcCs ttjttddB|d|S)NP_DETACHr)rspawnvpP_NOWAITr)r@rrr spawndetacheds rcCstjddS)Nr)sysargvrrrrgethgcmdrcCst|dSr)rrl)ri notindexedrrrmakedirrrcCrrr)keyrscoperrr lookupregrrcCr()zHide current shell window. Used to hide the window opened when starting asynchronous child process under Windows, unneeded on other systems. Nrrrrr hidewindowsr c@s2eZdZddZddZejZddZddZd S) cachestatcCst||_dSr)rrH)selfrirrr__init__rzcachestat.__init__cCs t|jjSr)rPrHst_ino)r rrr cacheables zcachestat.cacheablecCszQ|jj|jjkoP|jj|jjkoP|jj|jjkoP|jj|jjkoP|jj|jjkoP|jj|jjkoP|jj|jjkoP|jtj|jtjkoP|jtj |jtj kWSt y[YdSwr) rHrCr rr+rst_gidst_sizeST_MTIMEST_CTIMErr otherrrr__eq__s* zcachestat.__eq__cCs ||k Srrrrrr__ne__s zcachestat.__ne__N) __name__ __module__ __qualname__r robject__hash__rrrrrrr s  r cCs|ot|jS)z(check whether a stat result is a symlink)rHrIrCrrrr statislinksrcCs|o|jd@dkS)z1check whether a stat result is an executable filerBr)rCrrrr statisexecsrc Cs~z) z t|||}Wntjy'}z|jdtjkr"WYd}~qd}~wwWn ty3twttt 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 NotImplementedErrorTrN) selectrr@r EINTRrNotImplementedErrorsortedrsetsum)fdsresr]rrrpolls   r&c Cst|tj}|tjO}t|tj|}z+g} z|}|s!Wn||Wn ty0Ynwqd|Wt|tj|St|tj|w)z$Read all available data from a pipe.Tr ) fcntlF_GETFLr O_NONBLOCKF_SETFLrJappendrmrj)pipeflagsoldflagschunksrUrrrreadpipes"   $r0c Csttj|\}}d}z&|rtdtj}t||||r%t|W|r/t|dSdS|r9t|ww)z1Bind the UNIX domain socket to the specified pathN.) rrir'r O_DIRECTORYchdirbindfchdirro)sockridirnamerbakwdfdrrrbindunixsockets    r9)rrrr)NN)` __future__rr r'rrrrrrrHrrri18nrr rrrrrr importmodr rinormpathsamestatabspathlinkrrrNrKrq removedirs expandglobsrOispy3rr'r)r-r8rArErXr_r}rrrrrrrrrrr normcasespecsr normcasespecrisdarwinr3r!rrrr;rrrrrS_IFREGS_IFLNKrrrrrrrrrrr rr rrr&r0r9rrrrs              ,SH           "