From 8b4287d7b44e700baf308ab45fa5a2e1ae29e657 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Thu, 12 Nov 2020 10:44:00 -0800 Subject: [PATCH 1/2] Add _a_ Big Sur sucatalog to the list of DEFAULT_SUCATALOGS --- installinstallmacos.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/installinstallmacos.py b/installinstallmacos.py index bafe611..bf112f9 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -54,6 +54,9 @@ DEFAULT_SUCATALOGS = { '19': 'https://swscan.apple.com/content/catalogs/others/' 'index-10.15-10.14-10.13-10.12-10.11-10.10-10.9' '-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog', + '20': 'https://swscan.apple.com/content/catalogs/others/' + 'index-11-10.15-10.14-10.13-10.12-10.11-10.10-10.9' + '-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog', } SEED_CATALOGS_PLIST = ( From 03ef2ba0fed4a6e99de0a0acf7ea9e3949a47287 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Mon, 15 Feb 2021 18:14:52 -0700 Subject: [PATCH 2/2] Fix HTTP resume (#84) * Fix HTTP resume * Handle error 416 when resuming complete file * Line break for comment * Fix logic * ensure err.output is digits * amend comment * Support retry on error 412 --- installinstallmacos.py | 51 ++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index bf112f9..21b2929 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -264,23 +264,40 @@ def replicate_url(full_url, options = '-fL' else: options = '-sfL' - curl_cmd = ['/usr/bin/curl', options, - '--create-dirs', - '-o', local_file_path] - if not full_url.endswith(".gz"): - # stupid hack for stupid Apple behavior where it sometimes returns - # compressed files even when not asked for - curl_cmd.append('--compressed') - if not ignore_cache and os.path.exists(local_file_path): - curl_cmd.extend(['-z', local_file_path]) - if attempt_resume: - curl_cmd.extend(['-C', '-']) - curl_cmd.append(full_url) - print("Downloading %s..." % full_url) - try: - subprocess.check_call(curl_cmd) - except subprocess.CalledProcessError as err: - raise ReplicationError(err) + need_download = True + while need_download: + curl_cmd = ['/usr/bin/curl', options, + '--create-dirs', + '-o', local_file_path, + '-w', '%{http_code}'] + if not full_url.endswith(".gz"): + # stupid hack for stupid Apple behavior where it sometimes returns + # compressed files even when not asked for + curl_cmd.append('--compressed') + resumed = False + if not ignore_cache and os.path.exists(local_file_path): + if not attempt_resume: + curl_cmd.extend(['-z', local_file_path]) + else: + resumed = True + curl_cmd.extend(['-z', '-' + local_file_path, '-C', '-']) + curl_cmd.append(full_url) + print("Downloading %s..." % full_url) + need_download = False + try: + output = subprocess.check_output(curl_cmd) + except subprocess.CalledProcessError as err: + if not resumed or not err.output.isdigit(): + raise ReplicationError(err) + # HTTP error 416 on resume: the download is already complete and the + # file is up-to-date + # HTTP error 412 on resume: the file was updated server-side + if int(err.output) == 412: + print("Removing %s and retrying." % local_file_path) + os.unlink(local_file_path) + need_download = True + elif int(err.output) != 416: + raise ReplicationError(err) return local_file_path