Mercurial > hg
comparison hgext/lfs/blobstore.py @ 37692:10e5bb9678f4
lfs: gracefully handle aborts on the server when corrupt blobs are detected
The aborts weren't killing the server, but this seems cleaner. I'm not sure if
it matters to handle the remaining IOError in the test like this, for
consistency.
The error code still feels wrong (especially if the client is trying to download
a corrupt blob) but I don't see anything better in the RFCs, and this is already
used elsewhere because the Batch API spec specifically mentioned this as a
"Validation Error".
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 25 Feb 2018 14:07:13 -0500 |
parents | d241e6632669 |
children | ab04972a33ef |
comparison
equal
deleted
inserted
replaced
37691:d241e6632669 | 37692:10e5bb9678f4 |
---|---|
150 fp.write(chunk) | 150 fp.write(chunk) |
151 sha256.update(chunk) | 151 sha256.update(chunk) |
152 | 152 |
153 realoid = sha256.hexdigest() | 153 realoid = sha256.hexdigest() |
154 if realoid != oid: | 154 if realoid != oid: |
155 raise error.Abort(_('corrupt remote lfs object: %s') % oid) | 155 raise LfsCorruptionError(_('corrupt remote lfs object: %s') |
156 % oid) | |
156 | 157 |
157 self._linktousercache(oid) | 158 self._linktousercache(oid) |
158 | 159 |
159 def write(self, oid, data): | 160 def write(self, oid, data): |
160 """Write blob to local blobstore. | 161 """Write blob to local blobstore. |
524 return reduced.values() | 525 return reduced.values() |
525 | 526 |
526 def _verify(oid, content): | 527 def _verify(oid, content): |
527 realoid = hashlib.sha256(content).hexdigest() | 528 realoid = hashlib.sha256(content).hexdigest() |
528 if realoid != oid: | 529 if realoid != oid: |
529 raise error.Abort(_('detected corrupt lfs object: %s') % oid, | 530 raise LfsCorruptionError(_('detected corrupt lfs object: %s') % oid, |
530 hint=_('run hg verify')) | 531 hint=_('run hg verify')) |
531 | 532 |
532 def remote(repo, remote=None): | 533 def remote(repo, remote=None): |
533 """remotestore factory. return a store in _storemap depending on config | 534 """remotestore factory. return a store in _storemap depending on config |
534 | 535 |
535 If ``lfs.url`` is specified, use that remote endpoint. Otherwise, try to | 536 If ``lfs.url`` is specified, use that remote endpoint. Otherwise, try to |
571 raise error.Abort(_('lfs: unknown url scheme: %s') % scheme) | 572 raise error.Abort(_('lfs: unknown url scheme: %s') % scheme) |
572 return _storemap[scheme](repo, url) | 573 return _storemap[scheme](repo, url) |
573 | 574 |
574 class LfsRemoteError(error.RevlogError): | 575 class LfsRemoteError(error.RevlogError): |
575 pass | 576 pass |
577 | |
578 class LfsCorruptionError(error.Abort): | |
579 """Raised when a corrupt blob is detected, aborting an operation | |
580 | |
581 It exists to allow specialized handling on the server side.""" |