diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py index ed30934165c91c3438afa3ab347abfb605a68a92_aGdleHQvbGZzL2Jsb2JzdG9yZS5weQ==..fa9dd53eb23eb75607aaa59d329f78f2e5fe02b7_aGdleHQvbGZzL2Jsb2JzdG9yZS5weQ== 100644 --- a/hgext/lfs/blobstore.py +++ b/hgext/lfs/blobstore.py @@ -114,6 +114,26 @@ return self.vfs(oid, 'rb') + def download(self, oid, src): + """Read the blob from the remote source in chunks, verify the content, + and write to this local blobstore.""" + sha256 = hashlib.sha256() + + with self.vfs(oid, 'wb', atomictemp=True) as fp: + for chunk in util.filechunkiter(src, size=1048576): + fp.write(chunk) + sha256.update(chunk) + + realoid = sha256.hexdigest() + if realoid != oid: + raise error.Abort(_('corrupt remote lfs object: %s') % oid) + + # XXX: should we verify the content of the cache, and hardlink back to + # the local store on success, but truncate, write and link on failure? + if not self.cachevfs.exists(oid): + self.ui.note(_('lfs: adding %s to the usercache\n') % oid) + lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid)) + def write(self, oid, data, verify=True): """Write blob to local blobstore.""" if verify: