2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

move first mkstemp to exception safe location in get_file

This commit is contained in:
Eric Blundell 2018-03-20 16:30:48 -05:00
parent 4c9e4df532
commit f0c00c8801

View File

@ -2247,10 +2247,9 @@ class Client:
version=version version=version
) )
fd, file_name = tempfile.mkstemp()
limit = 1024 * 1024 limit = 1024 * 1024
offset = 0 offset = 0
file_name = None
try: try:
r = session.send( r = session.send(
@ -2261,6 +2260,8 @@ class Client:
) )
) )
fd, file_name = tempfile.mkstemp()
if isinstance(r, types.upload.File): if isinstance(r, types.upload.File):
with os.fdopen(fd, "wb") as f: with os.fdopen(fd, "wb") as f:
while True: while True:
@ -2374,10 +2375,11 @@ class Client:
except Exception as e: except Exception as e:
log.error(e, exc_info=True) log.error(e, exc_info=True)
try: if file_name:
os.remove(file_name) try:
except OSError: os.remove(file_name)
pass except OSError:
pass
else: else:
return file_name return file_name
finally: finally: