Mercurial > hg
changeset 51738:d17578f96e60
httppeer: simplify two-way stream cleanup
No need to conditionalize the cleanup if the filename is assigned outside the
exception handler. I suppose `fd` leaks if `os.fdopen()` fails, but that was
the case before too (and may trigger another exception in the `finally` block on
Windows, when the file is still open).
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 26 Jul 2024 21:54:07 -0400 |
parents | 48eb51494a7a |
children | 78f789a4c8a2 |
files | mercurial/httppeer.py |
diffstat | 1 files changed, 3 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httppeer.py Mon Jul 29 10:07:53 2024 +0200 +++ b/mercurial/httppeer.py Fri Jul 26 21:54:07 2024 -0400 @@ -520,10 +520,9 @@ os.unlink(tempname) def _calltwowaystream(self, cmd, fp, **args): - filename = None + # dump bundle to disk + fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") try: - # dump bundle to disk - fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") with os.fdopen(fd, "wb") as fh: d = fp.read(4096) while d: @@ -534,8 +533,7 @@ headers = {'Content-Type': 'application/mercurial-0.1'} return self._callstream(cmd, data=fp_, headers=headers, **args) finally: - if filename is not None: - os.unlink(filename) + os.unlink(filename) def _callcompressable(self, cmd, **args): return self._callstream(cmd, _compressible=True, **args)