equal
deleted
inserted
replaced
15 import re |
15 import re |
16 import socket |
16 import socket |
17 |
17 |
18 from mercurial.i18n import _ |
18 from mercurial.i18n import _ |
19 from mercurial.pycompat import getattr |
19 from mercurial.pycompat import getattr |
|
20 from mercurial.node import hex |
20 |
21 |
21 from mercurial import ( |
22 from mercurial import ( |
22 encoding, |
23 encoding, |
23 error, |
24 error, |
24 httpconnection as httpconnectionmod, |
25 httpconnection as httpconnectionmod, |
25 node, |
|
26 pathutil, |
26 pathutil, |
27 pycompat, |
27 pycompat, |
28 url as urlmod, |
28 url as urlmod, |
29 util, |
29 util, |
30 vfs as vfsmod, |
30 vfs as vfsmod, |
171 b"Response length (%s) does not match Content-Length " |
171 b"Response length (%s) does not match Content-Length " |
172 b"header (%d): likely server-side crash" |
172 b"header (%d): likely server-side crash" |
173 ) |
173 ) |
174 raise LfsRemoteError(_(msg) % (size, int(content_length))) |
174 raise LfsRemoteError(_(msg) % (size, int(content_length))) |
175 |
175 |
176 realoid = node.hex(sha256.digest()) |
176 realoid = hex(sha256.digest()) |
177 if realoid != oid: |
177 if realoid != oid: |
178 raise LfsCorruptionError( |
178 raise LfsCorruptionError( |
179 _(b'corrupt remote lfs object: %s') % oid |
179 _(b'corrupt remote lfs object: %s') % oid |
180 ) |
180 ) |
181 |
181 |
222 # Even if revlog will verify the content, it needs to be verified |
222 # Even if revlog will verify the content, it needs to be verified |
223 # now before making the hardlink to avoid propagating corrupt blobs. |
223 # now before making the hardlink to avoid propagating corrupt blobs. |
224 # Don't abort if corruption is detected, because `hg verify` will |
224 # Don't abort if corruption is detected, because `hg verify` will |
225 # give more useful info about the corruption- simply don't add the |
225 # give more useful info about the corruption- simply don't add the |
226 # hardlink. |
226 # hardlink. |
227 if verify or node.hex(hashlib.sha256(blob).digest()) == oid: |
227 if verify or hex(hashlib.sha256(blob).digest()) == oid: |
228 self.ui.note(_(b'lfs: found %s in the usercache\n') % oid) |
228 self.ui.note(_(b'lfs: found %s in the usercache\n') % oid) |
229 lfutil.link(self.cachevfs.join(oid), self.vfs.join(oid)) |
229 lfutil.link(self.cachevfs.join(oid), self.vfs.join(oid)) |
230 else: |
230 else: |
231 self.ui.note(_(b'lfs: found %s in the local lfs store\n') % oid) |
231 self.ui.note(_(b'lfs: found %s in the local lfs store\n') % oid) |
232 blob = self._read(self.vfs, oid, verify) |
232 blob = self._read(self.vfs, oid, verify) |
246 |
246 |
247 with self.open(oid) as fp: |
247 with self.open(oid) as fp: |
248 for chunk in util.filechunkiter(fp, size=1048576): |
248 for chunk in util.filechunkiter(fp, size=1048576): |
249 sha256.update(chunk) |
249 sha256.update(chunk) |
250 |
250 |
251 return oid == node.hex(sha256.digest()) |
251 return oid == hex(sha256.digest()) |
252 |
252 |
253 def has(self, oid): |
253 def has(self, oid): |
254 """Returns True if the local blobstore contains the requested blob, |
254 """Returns True if the local blobstore contains the requested blob, |
255 False otherwise.""" |
255 False otherwise.""" |
256 return self.cachevfs.exists(oid) or self.vfs.exists(oid) |
256 return self.cachevfs.exists(oid) or self.vfs.exists(oid) |
704 reduced[p.oid()] = p |
704 reduced[p.oid()] = p |
705 return reduced.values() |
705 return reduced.values() |
706 |
706 |
707 |
707 |
708 def _verify(oid, content): |
708 def _verify(oid, content): |
709 realoid = node.hex(hashlib.sha256(content).digest()) |
709 realoid = hex(hashlib.sha256(content).digest()) |
710 if realoid != oid: |
710 if realoid != oid: |
711 raise LfsCorruptionError( |
711 raise LfsCorruptionError( |
712 _(b'detected corrupt lfs object: %s') % oid, |
712 _(b'detected corrupt lfs object: %s') % oid, |
713 hint=_(b'run hg verify'), |
713 hint=_(b'run hg verify'), |
714 ) |
714 ) |