o ]Lb@spdZddlmZddlmZddlmZddlmZddl m Z ddl m Z Gd d d e ZGd d d eZd S)zCbase class for store implementations and store-related utility code)absolute_import)_)short)util)urlutil)lfutilc@s(eZdZdZddZddZddZdS) StoreErrorzZRaised when there is a problem getting files from or putting files to a central store.cCs||_||_||_||_dSN)filenamehashurldetail)selfr r r rrPut source file into the store so it can be retrieved by hash.abstract methodNotImplementedError)rsourcer rrrput3sz basestore.putcCr)zCheck to see if the store contains the given hashes. Given an iterable of hashes it returns a mapping from hash to bool.rr )rhashesrrrexists7szbasestore.existsc Csg}g}|j}d}|dd|D}|jtdtdt|dT}|D]F\}} |||d7}|td|| f|| sW|td || t |j f| |q$| || re| || fq$| |q$Wd ||fS1sxwY||fS) aGet 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.)rcSsh|]\}}|qSrr).0 _filenamer rrr Jz basestore.get..sgetting largefilessfiles)unittotalrsgetting %s:%s s'%s: largefile %s not available from %s N)rr% makeprogressrlenupdatenotegetwarnrrr append_gethash) rfilessuccessmissingrat availableprogressr r rrrr0<s:        z basestore.getc Cstt|jdt|j|}|d}tj||jjjd.}z ||||}Wnt yE}z|j | d}WYd}~nd}~wwWdn1sPwY||krq|dkrj|j t d|||ft|dSt||t|j|dS)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. s.tmp) createmodeNs*%s: data corruption (expected %s, got %s) FT)rmakedirsr storepathratomictempfilestorer;_getfiler rr1rrunlinkrenamelinktousercache)rr r storefilenametmpnametmpfilegothasherrrrrr3bs8    zbasestore._gethashFcCs|jtdt|t}g}|D]?}|j|}d|t|f}|D])}t |} | rQ||} | | f} | |vrQ| | t | } ||| | fq(q|||} t|}tdd|D}|rx|jtd||ft| S|jtd||ft| 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:%scSsh|]\}}|qSrr)r&fnamefnoderrrr(r)z#basestore.verify..s3verified contents of %d revisions of %d largefiles s4verified existence of %d revisions of %d largefiles )rstatusrr-setrrevrnoder splitstandinfilenodeadd readasstandinr2 _verifyfilesint)rrevscontentsverified filestocheckrMcctxcsetstandinr fctxkey expectedhashfailednumrevs numlfilesrrrverifysF       zbasestore.verifycCr)aFetch 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).rr )rrFr r rrrr@zbasestore._getfilecCr)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! rr )rrVrXrrrrSrczbasestore._verifyfilesN)F) rrrrr#r%r0r3rbr@rSrrrrr-s& ( rN)r __future__rmercurial.i18nrmercurial.noder mercurialrmercurial.utilsrr Exceptionr objectrrrrrs