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:
parent
4c9e4df532
commit
f0c00c8801
@ -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,10 +2375,11 @@ class Client:
|
||||
except Exception as e:
|
||||
log.error(e, exc_info=True)
|
||||
|
||||
try:
|
||||
os.remove(file_name)
|
||||
except OSError:
|
||||
pass
|
||||
if file_name:
|
||||
try:
|
||||
os.remove(file_name)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
return file_name
|
||||
finally:
|
||||
|
Loading…
x
Reference in New Issue
Block a user