##// 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,7 +298,7 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 = {
@@ -419,16 +420,18 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
429 ui.debug('%s\n'
428 % '\n'.join(sorted(str(req.info()).splitlines())))
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
434 # blobstore
432 localstore.download(oid, req)
435 localstore.download(oid, req)
433 else:
436 else:
434 while True:
437 while True:
@@ -437,7 +440,7 b' class _gitlfsremote(object):'
437 break
440 break
438 response += data
441 response += data
439 if response:
442 if response:
440 self.ui.debug('lfs %s response: %s' % (action, 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