
    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Jr  S SKJ	r	J
r
  S SKJrJrJr  S SKJr  SSKJrJr   " S	 S
5      r " S S5      rg)    )annotationsN)_)binhex)errorpycompatutil)hashutil   )	constantsshallowutilc                  |    \ rS rSrSS jrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rSrg)	basestore   c                   Xl         UR                  U l        X l        X0l        X@l        [
        R                  (       d  [        R                  " 5       OSU l	        U R                  R                  SS5      U l        U R                  R                  SSS5      U l        U R                  S;  a  SU l        U R                  S:X  a  SU l        U(       a"  [        R                  " U R                  U5        gg)	au  Creates a remotefilelog store object for the given repo name.

`path` - The file path where this store keeps its data
`reponame` - The name of the repo. This is used to partition data from
many repos.
`shared` - True if this store is a shared cache of data from the central
server, for many repos on this machine. False means this store is for
the local data for one repo.
N   remotefilelogs   validatecachelogs   validatecache   on)r      strict   offr   F)repoui_path	_reponame_sharedr   	iswindowsosgetuid_uidconfig_validatecachelog_validatecacher   mkstickygroupdir)selfr   pathreponameshareds        ?/usr/lib/python3/dist-packages/hgext/remotefilelog/basestore.py__init__basestore.__init__   s     	''
!'/'9'9BIIKt	!%1"
 #ggnn.
 &@@"'D&("'D(($7     c                   / nU H  u  p4U R                  X45      n[        R                  R                  U5      nU(       a)  U R                  S:X  a  U R                  US5      (       d  SnU(       a  Mn  UR                  X445        M     U$ )Nr   s   containsF)_getfilepathr   r$   existsr!   _validatekeyappend)r#   keysmissingnamenodefilepathr-   s          r'   
getmissingbasestore.getmissing6   sx    JD((4HWW^^H-F''94))(K@@6|,  r*   Nc                   U(       a%  UR                  [        R                  5      (       a  g U R                  (       aG  U R	                  5        H2  u  p4U H'  nUR                  XU5        UR                  XU5        M)     M4     g g N)getr   OPTION_PACKSONLYr   	_getfilesmarkdataentrymarkhistoryentry)r#   ledgeroptionsfilenamenodesr3   s         r'   
markledgerbasestore.markledgerH   se    w{{9#=#=>><<#'>>#3!D((>++DDA " $4 r*   c                   U R                   nUR                  R                  U / 5      nSnUR                  [	        S5      S[        U5      S9nU H  nUR                  (       d"  UR                  (       a^  UR                  (       aM  UR                  U5        U R                  UR                  UR                  5      n[        R                  " U5        US-  nM     UR                  5         U R!                  U R#                  5       5        g )Nr   s   cleaning up   filesunittotalr   )r   sourcesr9   makeprogressr   lengceddatarepackedhistoryrepackedupdater,   r@   r3   r	   	tryunlinkcomplete_cleanupdirectory_getrepocachepath)r#   r>   r   entriescountprogressentryr$   s           r'   cleanupbasestore.cleanupQ   s    WW..$$T2.??nHCL # 
 Ezze00U5J5J&((Dt$QJE  	 	t5578r*   c                   [        5       n[        5       n[        R                  R                  U5       H  u  pE[        R
                  " U5      (       aI  [        R                  R                  X5      nU R                  U5         [        R                  " U5        Mi  [        R                  " U5      (       d  M  UR                  S5      (       a  UR                  USS 5        M  UR                  U5        M     X#-
   H;  n[        R                  R                  XS-   5      n[        R                  " U5        M=     g! [         a     GM  f = f)zRemoves the empty directories and unnecessary files within the root
directory recursively. Note that this method does not remove the root
directory itself.   _oldN)setr	   osutillistdirstatS_ISDIRr   r$   joinrR   rmdirOSErrorS_ISREGendswithaddrP   )	r#   rootdiroldfiles
otherfilesr2   modedirpathr@   r4   s	            r'   rR   basestore._cleanupdirectorye   s    
 5U
 ++--g6JD||D!!'',,w5&&w/HHW% d##==))LLcr+NN4(! 7* !-Hww||G-?@HNN8$ .  s   D??
EEc              #    #    0 nU R                  5        H&  u  p#UR                  U/ 5      R                  U5        M(     U R                  UR	                  5       5      nUR                  5        H  u  pVXQU   4v   M     g7f)a  Return a list of (filename, [node,...]) for all the revisions that
exist in the store.

This is useful for obtaining a list of all the contents of the store
when performing a repack to another store, since the store API requires
name+node keys and not namehash+node keys.
N)	_listkeys
setdefaultr/   _resolvefilenamesr0   items)r#   existingfilenamehashr3   filenamemapr@   shas          r'   r;   basestore._getfiles   su      "&.."2Lb188> #3 ,,X]]_=(..0MHc]++ 1s   A>B c                h   U(       d  0 $ 0 n[        U5      nU R                  S   R                  5        HC  n[        R                  " U5      R                  5       nXS;   d  M.  XRU'   UR                  U5        ME     U R                  R                  5       R                  n[        [        U5      S-
  SS5       Hv  nU(       d    U$ UR                  UR                  U5      5      nU HC  n[        R                  " U5      R                  5       nXS;   d  M.  XRU'   UR                  U5        ME     Mx     U$ )zGiven a list of filename hashes that are present in the
remotefilelog store, return a mapping from filename->hash.

This is useful when converting remotefilelog blobs into other storage
formats.
s   tipr   )r]   r   manifestr
   sha1digestdiscard
unfiltered	changelograngerK   	readfilesr3   )	r#   hashes	filenamesmissingfilenamer@   rv   clrevfiless	            r'   rq   basestore._resolvefilenames   s    I	f+ 		&)224H--)002C%&)(#'',	 5 YY!!#--R1b"-C"  LL.E!mmH-446)*-h'#++C0	 "	 . r*   c                    U R                   (       a4  [        R                  R                  U R                  U R
                  5      $ U R                  $ r8   )r   r   r$   rb   r   r   )r#   s    r'   rS   basestore._getrepocachepath   s:     || GGLLT^^4	
 	
r*   c              #    #    [         R                  " U R                  5       5       H\  u  pnU HP  n[        U5      S:w  a  M  UnU R                  (       a  USS USS -   nOUSS n[        U5      [        U5      4v   MR     M^     g7f)zzList all the remotefilelog keys that exist in the store.

Returns a iterator of (filename hash, filecontent hash) tuples.
(   iiiNi)r   walkrS   rK   r   r   )r#   rootdirsr   r@   r3   rt   s          r'   ro   basestore._listkeys   s      "$)?)?)A!BD!x=B&<<#'C=4:#=L#':L<(#d)44 " "Cs   BBc                    [        U5      nU R                  (       a"  [        R                  " U R                  X5      nO[        R
                  " X5      n[        R                  R                  U R                  U5      $ r8   )
r   r   r   getcachekeyr   getlocalkeyr   r$   rb   r   )r#   r2   r3   keys       r'   r,   basestore._getfilepath   sQ    4y<<))$..$EC))$5Cww||DJJ,,r*   c           	        U R                  X5      n [        R                  " U5      nU R                  (       a  U R	                  XC5      (       dk  U R
                  (       a3  [        U R
                  S5       nUR                  SU-  5        S S S 5        [        R                  " X3S-   5        [        SU-  5      eU$ ! , (       d  f       N7= f! [         a    [        SX1[        U5      4-  5      ef = f)Nab+s   corrupt %s during read
   .corrupts   corrupt local cache file %ss   no file found at %s for %s:%s)r,   r   readfiler!   _validatedatar    openwriter   renameKeyErrorrd   r   )r#   r2   r3   r4   datafs         r'   _getdatabasestore._getdata   s    $$T0	''1D""4+=+=d+M+M))d44e< ;h FG =		({$:;=HII  =<  	0HCI3NN 	s$   A$C 7B=/C =
CC $C2c                   U R                  X5      n[        R                  " S5      n [        R                  R	                  U5      (       aU  US-   n[        R                  R	                  U5      (       a  [
        R                  " U5        [        R                  " XF5        [
        R                  " U R                  [        R                  R                  U5      5        [
        R                  " XCSS9  U R                  (       a9  U R                  US5      (       d"  [        R                   " [#        S5      U-  5      e[        R                  " U5        g ! [        R                  " U5        f = f)N   r[   T)readonlys   writes"   local cache write was corrupted %s)r,   r   umaskr$   r-   r   
unlinkfileshutilcopyr"   r   dirname	writefiler!   r.   r   Abortr   )r#   r2   r3   r   r4   oldumasknewfilenames          r'   addremotefilelognodebasestore.addremotefilelognode   s    $$T088E?	 ww~~h''&0 77>>+..**;7H2(("''//(2KL!!(4@""((8<<++?@8K  HHXBHHXs   DE E.c                   [         R                  R                  U R                  S5      n[	        US5       nUR                  [         R                  R                  U5      S-   5        SSS5        [         R                  " U5      nUR                  U R                  :X  a  [         R                  " US5        gg! , (       d  f       NW= f)zCall this to add the given repo path to the store's list of
repositories that are using it. This is useful later when doing garbage
collection, since it allows us to insecpt the repos to see what nodes
they want to be kept alive in the store.
   reposab   
Ni  )r   r$   rb   r   r   r   r   r`   st_uidr   chmod)r#   r$   	repospath	reposfilerepospathstats        r'   markrepobasestore.markrepo  s     GGLLX6	)T"iOOBGGOOD1E9: # 	*499,HHY' -	 #"s   2B::
Cc                ~   [        US5       nUR                  5       nS S S 5        U R                  WU5      (       a  gU R                  (       a4  [        U R                  S5       nUR	                  SX4-  5        S S S 5        [
        R                  " XS-   5        g! , (       d  f       N= f! , (       d  f       N9= f)NrbTr   s   corrupt %s during %s
r   F)r   readr   r    r   r   r   )r#   r$   actionr   r   s        r'   r.   basestore._validatekey  s    $668D  dD))!!d,,e41TNBC 5 			${*+  54s   B%B.
B+.
B<c                *    [        U5      S:  ab  [        R                  " U5      u  p4n[        U5      U::  a  gX4-  nXUS-    n[        R                  R                  U5      [        U5      :X  a  gg g! [        [        R                  4 a     gf = f)Nr   F   T)	rK   r   parsesizeflagsr   r$   basenamer   
ValueErrorBadRemotefilelogHeader)r#   r   r$   offsetsizeflagsdatanodes          r'   r   basestore._validatedata#  s    	4y1}&1&@&@&F#et9$  "5 77##D)S]: &  K>>? 		s   7A5 7A5 5BBc           	        U R                   nU R                  n[        R                  R	                  5       nSnSnSnSn[
        R
                  " 5       S-
  n	UR                  [        S5      SS9n
U
R                  S5        [        R                  " U5       H  u  pnU H  nUS:X  a  M  SU;   a  M  U
R                  U5        [        R                  R                  X5      n[        R                  R                  X5      nUS-  n [        R                  " U5      nUUR"                  -  nUU;   d  UR$                  U	:  a/  UR'                  UR$                  UU45        UUR"                  -  nM   [(        R*                  " U5        US-  nM     M     U
R-                  5         UR/                  S
S5      n	Xi:  a  Xi-
  nUR                  [        S5      SUS9n
SnU(       a~  Xi:  ay  US:  as  U
R                  U5        UR1                  5       u  nnn [(        R*                  " U5        UUR"                  -  nUS-  nUUR"                  -  nU(       a  Xi:  a  US:  a  Ms  U
R-                  5         UR3                  [        S5      UU[5        U5      S-  S-  S-  [5        U5      S-  S-  S-  4-  5        g ! [         a$    [        S	5      nUR!                  UU-  5         GME  f = f! [         a$    [        S	5      nUR!                  UU-  5         GMv  f = f! [         a#    [        S	5      nUR!                  UU-  5         GNf = f)Nr   iQ s   removing unnecessary filesrE   )rG   r   s   /packs/r   s0   warning: file %s was removed by another process
r   s
   cachelimits   enforcing cache limits   bytesrF   s8   finished: removed %d of %d files (%0.2f GB to %0.2f GB)
g      @)r   r   r   queuePriorityQueuetimerJ   r   rO   r   r   r$   rb   relpathr`   FileNotFoundErrorwarnst_sizest_atimeputr   r   rQ   configbytesr9   statusfloat)r#   keepkeysr   	cachepathr   originalsizer   rU   removedlimitrV   r   r   r   filer$   r   pathstatmsgexcessremovedexcessatimeoldpatholdpathstats                           r'   gcbasestore.gc:  s1   WWJJ	 ,,. 		|,??+,8 # 
 	!#!3D8# %&ww||D/ggood6
!wwt}H  0 00(?h&7&7%&?IIx00$ABH,,,D!#..t4 qLGI  "4L 	 /?<\F*+(& ' H MDLTAX..3iik+w+**73 +++1!4!44 DLTAX 
		JKl#f,v5>df$v-6		
a ) LC GGC$J' - !) d
+ !. ) +LC GGC'M*	+s6   J72K(L 7)K%$K%()LL)MM)r   r   r   r   r!   r    r   r   )Fr8   )__name__
__module____qualname____firstlineno__r(   r5   rB   rX   rR   r;   rq   rS   ro   r,   r   r   r   r.   r   r   __static_attributes__ r*   r'   r   r      sV    8>$B9( %D," D
5$-"4(.Y
r*   r   c                  0    \ rS rSrS rS r\S 5       rSrg)baseunionstorei  c                f    UR                  SS5      S-   U l        UR                  SS 5      U l        g )N
numretriesr   r   retrylog)r9   numattemptsr   )r#   argskwargss      r'   r(   baseunionstore.__init__  s0    
 "::lA6: 

:t4r*   c                p    U R                    H&  n[        US5      (       d  M  UR                  5         M(     g )Nmarkforrefresh)storeshasattrr   )r#   stores     r'   r   baseunionstore.markforrefresh  s*    [[Eu.//$$& !r*   c                   ^ ^ S mU U4S jnU$ )Nc                     g r8   r   )r   s    r'   noop&baseunionstore.retriable.<locals>.noop  s    r*   c                  > U R                   =(       d    TnTR                  nSnXPR                  :  aI  US:  a1  U" SU[        R                  " U5      4-  5        U R                  5         US-  n T" U /UQ70 UD6$ g ! [         a2    XPR                  :X  a   U" S[        R                  " U5      -  5        e  Of = fXPR                  :  a  M  g )Nr   s   re-attempting (n=%d) %s
r   s*   retries exhausted in %s, raising KeyError
)r   r   r   r   sysbytesr   r   )r#   r   r   r   funcnameifnr   s         r'   wrapped)baseunionstore.retriable.<locals>.wrapped  s    }},H{{HA&&&q54h//9:; '')Q	d4T4V44 '   ,,, J&//9:  - &&&s   1A> >9B:9B:r   )r  r  r   s   ` @r'   	retriablebaseunionstore.retriable  s    		. r*   )r   r   N)	r   r   r   r   r(   r   staticmethodr  r   r   r*   r'   r   r     s     5'
  r*   r   )
__future__r   r   r   r`   r   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r	   mercurial.utilsr
    r   r   r   r   r   r*   r'   <module>r     sE    " 	     # 
 %}
 }
@, ,r*   