hgext/largefiles/localstore.py
changeset 43076 2372284d9457
parent 30180 736f92c44656
child 43077 687b865b95ad
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    14 
    14 
    15 from . import (
    15 from . import (
    16     basestore,
    16     basestore,
    17     lfutil,
    17     lfutil,
    18 )
    18 )
       
    19 
    19 
    20 
    20 class localstore(basestore.basestore):
    21 class localstore(basestore.basestore):
    21     '''localstore first attempts to grab files out of the store in the remote
    22     '''localstore first attempts to grab files out of the store in the remote
    22     Mercurial repository.  Failing that, it attempts to grab the files from
    23     Mercurial repository.  Failing that, it attempts to grab the files from
    23     the user cache.'''
    24     the user cache.'''
    38         return retval
    39         return retval
    39 
    40 
    40     def _getfile(self, tmpfile, filename, hash):
    41     def _getfile(self, tmpfile, filename, hash):
    41         path = lfutil.findfile(self.remote, hash)
    42         path = lfutil.findfile(self.remote, hash)
    42         if not path:
    43         if not path:
    43             raise basestore.StoreError(filename, hash, self.url,
    44             raise basestore.StoreError(
    44                 _("can't get file locally"))
    45                 filename, hash, self.url, _("can't get file locally")
       
    46             )
    45         with open(path, 'rb') as fd:
    47         with open(path, 'rb') as fd:
    46             return lfutil.copyandhash(
    48             return lfutil.copyandhash(util.filechunkiter(fd), tmpfile)
    47                 util.filechunkiter(fd), tmpfile)
       
    48 
    49 
    49     def _verifyfiles(self, contents, filestocheck):
    50     def _verifyfiles(self, contents, filestocheck):
    50         failed = False
    51         failed = False
    51         for cset, filename, expectedhash in filestocheck:
    52         for cset, filename, expectedhash in filestocheck:
    52             storepath, exists = lfutil.findstorepath(self.repo, expectedhash)
    53             storepath, exists = lfutil.findstorepath(self.repo, expectedhash)
    53             if not exists:
    54             if not exists:
    54                 storepath, exists = lfutil.findstorepath(
    55                 storepath, exists = lfutil.findstorepath(
    55                     self.remote, expectedhash)
    56                     self.remote, expectedhash
       
    57                 )
    56             if not exists:
    58             if not exists:
    57                 self.ui.warn(
    59                 self.ui.warn(
    58                     _('changeset %s: %s references missing %s\n')
    60                     _('changeset %s: %s references missing %s\n')
    59                     % (cset, filename, storepath))
    61                     % (cset, filename, storepath)
       
    62                 )
    60                 failed = True
    63                 failed = True
    61             elif contents:
    64             elif contents:
    62                 actualhash = lfutil.hashfile(storepath)
    65                 actualhash = lfutil.hashfile(storepath)
    63                 if actualhash != expectedhash:
    66                 if actualhash != expectedhash:
    64                     self.ui.warn(
    67                     self.ui.warn(
    65                         _('changeset %s: %s references corrupted %s\n')
    68                         _('changeset %s: %s references corrupted %s\n')
    66                         % (cset, filename, storepath))
    69                         % (cset, filename, storepath)
       
    70                     )
    67                     failed = True
    71                     failed = True
    68         return failed
    72         return failed