From 7fdd039bee20cec9ae96ef1e00db5649910a92ab Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 7 Sep 2018 15:59:59 +0200 Subject: [PATCH] donate-cpu.py: Fix crash when wget destination file does not exist. (#1368) When os.remove() tried to remove a file that did not exist (which is the case when the script is started for the first time or the working directory has been cleared) a FileNotFoundError was issued and the script just crashed. --- tools/donate-cpu.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index e635f2368..a251e4762 100644 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -126,7 +126,12 @@ def removeTree(folderName): def wget(url, destfile): - os.remove(destfile) + if os.path.exists(destfile): + if os.path.isfile(destfile): + os.remove(destfile) + else: + print('Error: ' + destfile + ' exists but it is not a file! Please check the path and delete it manually.') + sys.exit(1) subprocess.call( ['wget', '--tries=10', '--timeout=300', '-O', destfile, url]) if os.path.isfile(destfile):