hgext/largefiles/remotestore.py
changeset 19004 6614e5e24e66
parent 19003 ad993cb7bbb1
child 19008 9d33d6e0d442
equal deleted inserted replaced
19003:ad993cb7bbb1 19004:6614e5e24e66
    56         elif stat != 0:
    56         elif stat != 0:
    57             raise RuntimeError('error getting file: unexpected response from '
    57             raise RuntimeError('error getting file: unexpected response from '
    58                                'statlfile (%r)' % stat)
    58                                'statlfile (%r)' % stat)
    59 
    59 
    60         try:
    60         try:
    61             length, infile = self._get(hash)
    61             chunks = self._get(hash)
    62         except urllib2.HTTPError, e:
    62         except urllib2.HTTPError, e:
    63             # 401s get converted to util.Aborts; everything else is fine being
    63             # 401s get converted to util.Aborts; everything else is fine being
    64             # turned into a StoreError
    64             # turned into a StoreError
    65             raise basestore.StoreError(filename, hash, self.url, str(e))
    65             raise basestore.StoreError(filename, hash, self.url, str(e))
    66         except urllib2.URLError, e:
    66         except urllib2.URLError, e:
    69             # all fail too.
    69             # all fail too.
    70             raise util.Abort('%s: %s' % (self.url, e.reason))
    70             raise util.Abort('%s: %s' % (self.url, e.reason))
    71         except IOError, e:
    71         except IOError, e:
    72             raise basestore.StoreError(filename, hash, self.url, str(e))
    72             raise basestore.StoreError(filename, hash, self.url, str(e))
    73 
    73 
    74         # Mercurial does not close its SSH connections after writing a stream
    74         return lfutil.copyandhash(chunks, tmpfile)
    75         if length is not None:
       
    76             infile = lfutil.limitreader(infile, length)
       
    77         try:
       
    78             return lfutil.copyandhash(util.filechunkiter(infile, 128 * 1024),
       
    79                                       tmpfile)
       
    80         finally:
       
    81             infile.close()
       
    82 
    75 
    83     def _verifyfile(self, cctx, cset, contents, standin, verified):
    76     def _verifyfile(self, cctx, cset, contents, standin, verified):
    84         filename = lfutil.splitstandin(standin)
    77         filename = lfutil.splitstandin(standin)
    85         if not filename:
    78         if not filename:
    86             return False
    79             return False