
    q&f                     n    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
  G d d	e      Z G d
 d      Zy)zCbase class for store implementations and store-related utility code    )_)short)util)urlutil   )lfutilc                   "    e Zd ZdZd Zd Zd Zy)
StoreErrorzZRaised when there is a problem getting files from or putting
    files to a central store.c                 <    || _         || _        || _        || _        y N)filenamehashurldetail)selfr   r   r   r   s        </usr/lib/python3/dist-packages/hgext/largefiles/basestore.py__init__zStoreError.__init__   s     	    c                     t        d      | j                  t        j                  | j                        | j
                  | j                  fz  S )Ns0   error getting id %s from url %s for file %s: %s
)r   r   r   hidepasswordr   r   r   r   s    r   longmessagezStoreError.longmessage    sB    EFII  *MMKK	J
 
 	
r   c                 ^    dt        j                  | j                        | j                  fz  S )Ns   %s: %s)r   r   r   r   r   s    r   __str__zStoreError.__str__(   s%    G00:DKKHHHr   N)__name__
__module____qualname____doc__r   r   r    r   r   r
   r
      s    !
Ir   r
   c                   >    e Zd Zd Zd Zd Zd Zd Zd
dZd Z	d Z
y	)	basestorec                 .    || _         || _        || _        y r   )uirepor   )r   r#   r$   r   s       r   r   zbasestore.__init__-   s    	r   c                     t        d      )z>Put source file into the store so it can be retrieved by hash.   abstract methodNotImplementedError)r   sourcer   s      r   putzbasestore.put2   s    !"455r   c                     t        d      )zCheck to see if the store contains the given hashes. Given an
        iterable of hashes it returns a mapping from hash to bool.r&   r'   )r   hashess     r   existszbasestore.exists6   s     ""455r   c           
         g }g }| j                   }d}| j                  |D ch c]  \  }}|	 c}}      }|j                  t        d      t        d      t	        |            5 }	|D ]  \  }
}|	j                  |       |dz  }|j                  t        d      |
|fz         |j                  |      sO|j                  t        d      |
|t        j                  | j                        fz         |j                  |
       | j                  |
|      r|j                  |
|f       |j                  |
        	 ddd       ||fS c c}}w # 1 sw Y   ||fS xY w)	a  Get the specified largefiles from the store and write to local
        files under repo.root.  files is a list of (filename, hash)
        tuples.  Return (success, missing), lists of files successfully
        downloaded and those not found in the store.  success is a list
        of (filename, hash) tuples; missing is a list of filenames that
        we could not get.  (The detailed error message will already have
        been presented to the user, so missing is just supplied as a
        summary.)r   s   getting largefiless   files)unittotalr   s   getting %s:%s
s'   %s: largefile %s not available from %s
N)r#   r-   makeprogressr   lenupdatenotegetwarnr   r   r   append_gethash)r   filessuccessmissingr#   at	_filenamer   	availableprogressr   s              r   r5   zbasestore.get;   sS    WWKKu E*;9d EF	__#$1X;c%j  
 	-"' -$#a,-40@@A }}T*GGEF#T7+?+?+IJK NN8,==40NNHd#34NN8,!-	-* !!- !F	-* !!s   E

&CEEc                    t        j                  t        j                  | j                  d             t        j                  | j                  |      }|dz   }t        j
                  || j                  j                  j                        5 }	 | j                  |||      }ddd       |k7  rE|dk7  r*| j                  j                  t        d      |||fz         t        j                  |       yt        j                  ||       t        j                   | j                  |       y# t        $ r5}| j                  j                  |j                                d}Y d}~d}~ww xY w# 1 sw Y   xY w)zGet file with the provided hash and store it in the local repo's
        store and in the usercache.
        filename is for informational messages only.
        r   s   .tmp)
createmodeNs*   %s: data corruption (expected %s, got %s)
FT)r   makedirsr   	storepathr$   atomictempfilestorerA   _getfiler
   r#   r6   r   r   unlinkrenamelinktousercache)r   r   r   storefilenametmpnametmpfilegothasherrs           r   r8   zbasestore._gethasha   s-   
 	f&&tyy#67((D9')  		 : :
 	--4@		 d?#~DEw/0 KK G]+tyy$/  S__./	 	s0   E-D,,	E*5+E% E-%E**E--E6c                 >   | j                   j                  t        d      t        |      z         t	               }g }|D ]  }| j
                  |   }d|j                         t        |j                               fz  }|D ]p  }t        j                  |      }	|	s||   }
|	|
j                         f}||vs7|j                  |       t        j                  |
      }|j                  ||	|f       r  | j                  ||      }t        |      }t        |D ch c]  \  }}|	 c}}      }|r4| j                   j                  t        d      ||fz         t!        |      S | j                   j                  t        d      ||fz         t!        |      S c c}}w )zVerify the existence (and, optionally, contents) of every big
        file revision referenced by every changeset in revs.
        Return 0 if all is well, non-zero on any errors.s'   searching %d changesets for largefiles
s   %d:%ss3   verified contents of %d revisions of %d largefiles
s4   verified existence of %d revisions of %d largefiles
)r#   statusr   r2   setr$   revr   noder   splitstandinfilenodeaddreadasstandinr7   _verifyfilesint)r   revscontentsverifiedfilestocheckrR   cctxcsetstandinr   fctxkeyexpectedhashfailednumrevsfnamefnode	numlfiless                     r   verifyzbasestore.verify   s   
 	9:SYF	
 5 	LC99S>Dtxxz5+=>>D L!..w7=D#T]]_5C(* S)'-';';D'A$++T8\,JKL		L ""8\:h-X>>E5>?	GGNNIJI&' 6{	 GGNNJKI&' 6{ ?s   F
c                     t        d      )a  Fetch one revision of one file from the store and write it
        to tmpfile.  Compute the hash of the file on-the-fly as it
        downloads and return the hash.  Close tmpfile.  Raise
        StoreError if unable to download the file (e.g. it does not
        exist in the store).r&   r'   )r   rL   r   r   s       r   rF   zbasestore._getfile        ""455r   c                     t        d      )zPerform the actual verification of files in the store.
        'contents' controls verification of content hash.
        'filestocheck' is list of files to check.
        Returns _true_ if any problems are found!
        r&   r'   )r   r[   r]   s      r   rX   zbasestore._verifyfiles   rk   r   N)F)r   r   r   r   r*   r-   r5   r8   ri   rF   rX   r   r   r   r!   r!   ,   s,    
66
$"L>&P66r   r!   N)r   mercurial.i18nr   mercurial.noder   	mercurialr   mercurial.utilsr    r   	Exceptionr
   r!   r   r   r   <module>rs      s8    J     I I,J6 J6r   