Mercurial > public > mercurial-scm > hg
comparison hgext/lfs/blobstore.py @ 37217:b00bd974eef5
lfs: drop a duplicate blob verification method
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 31 Mar 2018 00:02:31 -0400 |
parents | c37c47e47a95 |
children | 67db84842356 |
comparison
equal
deleted
inserted
replaced
37216:d2bd29dffc6c | 37217:b00bd974eef5 |
---|---|
314 headers = obj['actions'][action].get('header', {}).items() | 314 headers = obj['actions'][action].get('header', {}).items() |
315 | 315 |
316 request = util.urlreq.request(href) | 316 request = util.urlreq.request(href) |
317 if action == 'upload': | 317 if action == 'upload': |
318 # If uploading blobs, read data from local blobstore. | 318 # If uploading blobs, read data from local blobstore. |
319 with localstore.open(oid) as fp: | 319 if not localstore.verify(oid): |
320 _verifyfile(oid, fp) | 320 raise error.Abort(_('detected corrupt lfs object: %s') % oid, |
321 hint=_('run hg verify')) | |
321 request.data = filewithprogress(localstore.open(oid), None) | 322 request.data = filewithprogress(localstore.open(oid), None) |
322 request.get_method = lambda: 'PUT' | 323 request.get_method = lambda: 'PUT' |
323 | 324 |
324 for k, v in headers: | 325 for k, v in headers: |
325 request.add_header(k, v) | 326 request.add_header(k, v) |
489 realoid = hashlib.sha256(content).hexdigest() | 490 realoid = hashlib.sha256(content).hexdigest() |
490 if realoid != oid: | 491 if realoid != oid: |
491 raise error.Abort(_('detected corrupt lfs object: %s') % oid, | 492 raise error.Abort(_('detected corrupt lfs object: %s') % oid, |
492 hint=_('run hg verify')) | 493 hint=_('run hg verify')) |
493 | 494 |
494 def _verifyfile(oid, fp): | |
495 sha256 = hashlib.sha256() | |
496 while True: | |
497 data = fp.read(1024 * 1024) | |
498 if not data: | |
499 break | |
500 sha256.update(data) | |
501 realoid = sha256.hexdigest() | |
502 if realoid != oid: | |
503 raise error.Abort(_('detected corrupt lfs object: %s') % oid, | |
504 hint=_('run hg verify')) | |
505 | |
506 def remote(repo): | 495 def remote(repo): |
507 """remotestore factory. return a store in _storemap depending on config""" | 496 """remotestore factory. return a store in _storemap depending on config""" |
508 url = util.url(repo.ui.config('lfs', 'url') or '') | 497 url = util.url(repo.ui.config('lfs', 'url') or '') |
509 scheme = url.scheme | 498 scheme = url.scheme |
510 if scheme not in _storemap: | 499 if scheme not in _storemap: |