mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +00:00
move first mkstemp to exception safe location in get_file
This commit is contained in:
parent
4c9e4df532
commit
f0c00c8801
1 changed files with 8 additions and 6 deletions
|
|
@ -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…
Reference in a new issue