From 2b33f239900fa337831645c3d9d67d6ec8a3b2b2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Mar 2018 19:25:23 +0100 Subject: [PATCH] Check whether get_file failed or not #37 If it failed, also delete any eventual temporary file --- pyrogram/client/client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 20ac58bc..5a16f482 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -567,6 +567,9 @@ class Client: progress=progress ) + if tmp_file_name is None: + return None + if file_name is not None: path[0] = "downloads/{}".format(file_name) @@ -2334,11 +2337,16 @@ class Client: if len(chunk) < limit: break except Exception as e: - log.error(e) + raise e finally: cdn_session.stop() except Exception as e: log.error(e) + + try: + os.remove(file_name) + except OSError: + pass else: return file_name finally: