
    	^c                     |    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dS )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dS )
StoreErrorzZRaised when there is a problem getting files from or putting
    files to a central store.c                 >    || _         || _        || _        || _        d S 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                 z    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    s=    EFFI **MK	J
 
 	
r   c                 H    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::DKHHHr   N)__name__
__module____qualname____doc__r   r   r    r   r   r
   r
      sP        ! !  
 
 
I I I I 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
d
S )	basestorec                 0    || _         || _        || _        d S 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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55r   c           
         g }g }| j         }d}|                     d |D                       }|                    t          d          t          d          t	          |                    5 }|D ]\  }}	|                    |           |dz  }|                    t          d          ||	fz             |                    |	          sU|                    t          d          ||	t          j
        | j                  fz             |                    |           |                     ||	          r|                    ||	f           |                    |           	 d	d	d	           n# 1 swxY w Y   ||fS )
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   c                     h | ]\  }}|S r   r   ).0	_filenamer   s      r   	<setcomp>z basestore.get.<locals>.<setcomp>I   s     E E E*;9d E E Er   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	availableprogressr   r   s
             r   r9   zbasestore.get;   s    WKK E Eu E E EFF	__#$$1X;;c%jj  
 
 	-"' - -$###a,--40@@AAA }}T** GGEFF#T7+?+I+IJK   NN8,,,==400 -NNHd#34444NN8,,,,!-	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-* !!s   ,C7E00E47E4c                    t          j        t          j        | j        d                     t          j        | j        |          }|dz   }t          j        || j        j        j                  5 }	 |                     |||          }nE# t          $ r8}| j
                            |                                           d}Y d}~nd}~ww xY wddd           n# 1 swxY w Y   ||k    rI|dk    r-| j
                            t          d          |||fz             t          j        |           dS t          j        ||           t          j        | j        |           dS )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storerD   _getfiler
   r#   r:   r   r   unlinkrenamelinktousercache)r   r   r   storefilenametmpnametmpfilegothasherrs           r   r<   zbasestore._gethasha   s   
 	f&ty#66777(D99') 	 :
 
 
 	--4@@   S__..///	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d??#~~DEEw/0   K   5G]+++ty$///ts<   1C3B
C
C.CCCCC #C Fc                 p   | j                             t          d          t          |          z             t	                      }g }|D ]}| j        |         }d|                                t          |                                          fz  }|D ]{}t          j
        |          }	|	rc||         }
|	|
                                f}||vrA|                    |           t          j        |
          }|                    ||	|f           ||                     ||          }t          |          }t          d |D                       }|r-| j                             t          d          ||fz             n,| j                             t          d          ||fz             t!          |          S )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:%sc                     h | ]\  }}|S r   r   )r0   fnamefnodes      r   r2   z#basestore.verify.<locals>.<setcomp>   s    >>>>E5>>>r   s3   verified contents of %d revisions of %d largefiles
s4   verified existence of %d revisions of %d largefiles
)r#   statusr   r6   setr$   revr   noder   splitstandinfilenodeaddreadasstandinr;   _verifyfilesint)r   revscontentsverifiedfilestocheckrX   cctxcsetstandinr   fctxkeyexpectedhashfailednumrevs	numlfiless                   r   verifyzbasestore.verify   s   
 	9::SYYF	
 	
 	
 55 	L 	LC9S>Dtxxzz5+=+=>>D L L!.w77 L=D#T]]__5C(** S)))'-';D'A'A$++T8\,JKKKL ""8\::h-->>X>>>??	 		GNNIJJI&'   
 GNNJKKI&'   6{{r   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   rO   r   r   s       r   rI   zbasestore._getfile        ""45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   ra   rc   s      r   r^   zbasestore._verifyfiles   ro   r   N)F)r   r   r   r   r*   r-   r9   r<   rm   rI   r^   r   r   r   r!   r!   ,   s          
6 6 66 6 6
$" $" $"L  >& & & &P6 6 66 6 6 6 6r   r!   N)r   mercurial.i18nr   mercurial.noder   	mercurialr   mercurial.utilsr    r   	Exceptionr
   r!   r   r   r   <module>rw      s    J I                                   I I I I I I I I,J6 J6 J6 J6 J6 J6 J6 J6 J6 J6r   