2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 04:48:06 +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
)
fd, file_name = tempfile.mkstemp()
limit = 1024 * 1024
offset = 0
file_name = None
try:
r = session.send(
@ -2261,6 +2260,8 @@ class Client:
)
)
fd, file_name = tempfile.mkstemp()
if isinstance(r, types.upload.File):
with os.fdopen(fd, "wb") as f:
while True:
@ -2374,6 +2375,7 @@ class Client:
except Exception as e:
log.error(e, exc_info=True)
if file_name:
try:
os.remove(file_name)
except OSError: