##// END OF EJS Templates
httppeer: use context manager when writing temporary bundle to send...
Martin von Zweigbergk -
r43118:58f73e9c default
parent child Browse files
Show More
@@ -490,18 +490,16 b' class httppeer(wireprotov1peer.wirepeer)'
490 os.unlink(tempname)
490 os.unlink(tempname)
491
491
492 def _calltwowaystream(self, cmd, fp, **args):
492 def _calltwowaystream(self, cmd, fp, **args):
493 fh = None
494 fp_ = None
493 fp_ = None
495 filename = None
494 filename = None
496 try:
495 try:
497 # dump bundle to disk
496 # dump bundle to disk
498 fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
497 fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
499 fh = os.fdopen(fd, r"wb")
498 with os.fdopen(fd, r"wb") as fh:
500 d = fp.read(4096)
499 d = fp.read(4096)
501 while d:
500 while d:
502 fh.write(d)
501 fh.write(d)
503 d = fp.read(4096)
502 d = fp.read(4096)
504 fh.close()
505 # start http push
503 # start http push
506 fp_ = httpconnection.httpsendfile(self.ui, filename, "rb")
504 fp_ = httpconnection.httpsendfile(self.ui, filename, "rb")
507 headers = {r'Content-Type': r'application/mercurial-0.1'}
505 headers = {r'Content-Type': r'application/mercurial-0.1'}
@@ -509,8 +507,7 b' class httppeer(wireprotov1peer.wirepeer)'
509 finally:
507 finally:
510 if fp_ is not None:
508 if fp_ is not None:
511 fp_.close()
509 fp_.close()
512 if fh is not None:
510 if filename is not None:
513 fh.close()
514 os.unlink(filename)
511 os.unlink(filename)
515
512
516 def _callcompressable(self, cmd, **args):
513 def _callcompressable(self, cmd, **args):
General Comments 0
You need to be logged in to leave comments. Login now