From 9e4208becb775a69014c2e02b6a10f899efde1e7 Mon Sep 17 00:00:00 2001 From: Suresh V Date: Tue, 17 Sep 2013 23:14:42 +0530 Subject: implement for all downloaders and check file existence before removing --- ez_setup.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ez_setup.py') diff --git a/ez_setup.py b/ez_setup.py index 03458b70..945f55d9 100644 --- a/ez_setup.py +++ b/ez_setup.py @@ -162,7 +162,12 @@ def download_file_powershell(url, target): '-Command', "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(), ] - subprocess.check_call(cmd) + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + if os.access(target, os.F_OK): + os.unlink(target) + raise def has_powershell(): if platform.system() != 'Windows': @@ -182,7 +187,12 @@ download_file_powershell.viable = has_powershell def download_file_curl(url, target): cmd = ['curl', url, '--silent', '--output', target] - subprocess.check_call(cmd) + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + if os.access(target, os.F_OK): + os.unlink(target) + raise def has_curl(): cmd = ['curl', '--version'] @@ -203,7 +213,8 @@ def download_file_wget(url, target): try: subprocess.check_call(cmd) except subprocess.CalledProcessError: - os.unlink(target) + if os.access(target, os.F_OK): + os.unlink(target) raise def has_wget(): -- cgit v1.2.3