##// END OF EJS Templates
lfs: ensure that the return of urlopener.open() is closed...
Matt Harbison -
r40701:fb379b78 default
parent child Browse files
Show More
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import contextlib
10 import errno
11 import errno
11 import hashlib
12 import hashlib
12 import json
13 import json
@@ -297,8 +298,8 b' class _gitlfsremote(object):'
297 batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
298 batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
298 batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
299 batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
299 try:
300 try:
300 rsp = self.urlopener.open(batchreq)
301 with contextlib.closing(self.urlopener.open(batchreq)) as rsp:
301 rawjson = rsp.read()
302 rawjson = rsp.read()
302 except util.urlerr.httperror as ex:
303 except util.urlerr.httperror as ex:
303 hints = {
304 hints = {
304 400: _('check that lfs serving is enabled on %s and "%s" is '
305 400: _('check that lfs serving is enabled on %s and "%s" is '
@@ -419,25 +420,27 b' class _gitlfsremote(object):'
419
420
420 response = b''
421 response = b''
421 try:
422 try:
422 req = self.urlopener.open(request)
423 with contextlib.closing(self.urlopener.open(request)) as req:
423
424 ui = self.ui # Shorten debug lines
424 if self.ui.debugflag:
425 if self.ui.debugflag:
425 self.ui.debug('Status: %d\n' % req.status)
426 ui.debug('Status: %d\n' % req.status)
426 # lfs-test-server and hg serve return headers in different order
427 # lfs-test-server and hg serve return headers in different
427 self.ui.debug('%s\n'
428 # order
428 % '\n'.join(sorted(str(req.info()).splitlines())))
429 ui.debug('%s\n'
430 % '\n'.join(sorted(str(req.info()).splitlines())))
429
431
430 if action == 'download':
432 if action == 'download':
431 # If downloading blobs, store downloaded data to local blobstore
433 # If downloading blobs, store downloaded data to local
432 localstore.download(oid, req)
434 # blobstore
433 else:
435 localstore.download(oid, req)
434 while True:
436 else:
435 data = req.read(1048576)
437 while True:
436 if not data:
438 data = req.read(1048576)
437 break
439 if not data:
438 response += data
440 break
439 if response:
441 response += data
440 self.ui.debug('lfs %s response: %s' % (action, response))
442 if response:
443 ui.debug('lfs %s response: %s' % (action, response))
441 except util.urlerr.httperror as ex:
444 except util.urlerr.httperror as ex:
442 if self.ui.debugflag:
445 if self.ui.debugflag:
443 self.ui.debug('%s: %s\n' % (oid, ex.read()))
446 self.ui.debug('%s: %s\n' % (oid, ex.read()))
General Comments 0
You need to be logged in to leave comments. Login now