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.
This commit is contained in:
Sebastian 2018-09-07 15:59:59 +02:00 committed by GitHub
parent 5a2362b2a0
commit 7fdd039bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -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):