From 6c56bc6d8b266f726f811f542dd84b55fbed5b4e Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 14 Sep 2020 18:18:52 +0300 Subject: [PATCH 01/19] fixing the cli option retry_download_count to support simulator --- lib/xcode/install.rb | 2 +- lib/xcode/install/simulators.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 78f25bbf..04cd588e 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -59,7 +59,7 @@ def fetch(url: nil, progress_log_file = File.join(CACHE_DIR, "progress.#{Time.now.to_i}.progress") FileUtils.rm_f(progress_log_file) - retry_options = ['--retry', '3'] + retry_options = ['--retry', retry_download_count] command = [ 'curl', '--disable', diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index 99cbafed..cdaa3750 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -10,7 +10,8 @@ def self.options [['--install=name', 'Install simulator beginning with name, e.g. \'iOS 8.4\', \'tvOS 9.0\'.'], ['--force', 'Install even if the same version is already installed.'], ['--no-install', 'Only download DMG, but do not install it.'], - ['--no-progress', 'Don’t show download progress.']].concat(super) + ['--no-progress', 'Don’t show download progress.'], + ['--retry-download-count', 'Count of retrying download when curl is failed.']].concat(super) end def initialize(argv) @@ -19,6 +20,7 @@ def initialize(argv) @force = argv.flag?('force', false) @should_install = argv.flag?('install', true) @progress = argv.flag?('progress', true) + @retry_download_count = argv.option('retry-download-count', '3') super end @@ -42,7 +44,7 @@ def install simulator = filtered_simulators.first fail Informative, "#{simulator.name} is already installed." if simulator.installed? && !@force puts "Installing #{simulator.name} for Xcode #{simulator.xcode.bundle_version}..." - simulator.install(@progress, @should_install) + simulator.install(@progress, @should_install, @retry_download_count.to_i) else puts "[!] More than one simulator matching #{@install} was found. Please specify the full version.".ansi.red filtered_simulators.each do |candidate| From 30433495db4832bbbc8e9d95fd8115d19927b453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Mon, 14 Sep 2020 23:02:08 +0300 Subject: [PATCH 02/19] Update lib/xcode/install/simulators.rb Co-authored-by: freddi(Yuki Aki) --- lib/xcode/install/simulators.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index cdaa3750..d58effe5 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -44,6 +44,7 @@ def install simulator = filtered_simulators.first fail Informative, "#{simulator.name} is already installed." if simulator.installed? && !@force puts "Installing #{simulator.name} for Xcode #{simulator.xcode.bundle_version}..." + fail Informative, "Invalid Retry: `#{@retry_download_count} is not positive number.`" if (@retry_download_count =~ /\A[0-9]*\z/).nil? simulator.install(@progress, @should_install, @retry_download_count.to_i) else puts "[!] More than one simulator matching #{@install} was found. Please specify the full version.".ansi.red From 0f964587f99c6546dba8b3eaa7edfd36d9ad5075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Mon, 14 Sep 2020 23:02:57 +0300 Subject: [PATCH 03/19] Update lib/xcode/install/simulators.rb Co-authored-by: JP Simard --- lib/xcode/install/simulators.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index d58effe5..9df73484 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -11,7 +11,7 @@ def self.options ['--force', 'Install even if the same version is already installed.'], ['--no-install', 'Only download DMG, but do not install it.'], ['--no-progress', 'Don’t show download progress.'], - ['--retry-download-count', 'Count of retrying download when curl is failed.']].concat(super) + ['--retry-download-count', 'Count of retrying download when the curl operation fails.']].concat(super) end def initialize(argv) From 434624435e265c1060291f97e64ab86d9051124b Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 14 Sep 2020 23:39:33 +0300 Subject: [PATCH 04/19] change option name to number-of-try --- lib/xcode/install.rb | 26 +++++++++++++------------- lib/xcode/install/install.rb | 8 ++++---- lib/xcode/install/simulators.rb | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 04cd588e..34fe5c7b 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -25,7 +25,7 @@ class Curl # @param progress: parse and show the progress? # @param progress_block: A block that's called whenever we have an updated progress % # the parameter is a single number that's literally percent (e.g. 1, 50, 80 or 100) - # @param retry_download_count: A count to retry the downloading Xcode dmg/xip + # @param number_of_try: A count to retry the downloading Xcode dmg/xip # rubocop:disable Metrics/AbcSize def fetch(url: nil, directory: nil, @@ -33,7 +33,7 @@ def fetch(url: nil, output: nil, progress: nil, progress_block: nil, - retry_download_count: 3) + number_of_try: 3) options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] uri = URI.parse(url) @@ -59,12 +59,10 @@ def fetch(url: nil, progress_log_file = File.join(CACHE_DIR, "progress.#{Time.now.to_i}.progress") FileUtils.rm_f(progress_log_file) - retry_options = ['--retry', retry_download_count] command = [ 'curl', '--disable', *options, - *retry_options, '--location', '--continue-at', '-', @@ -80,7 +78,7 @@ def fetch(url: nil, # "Partial file. Only a part of the file was transferred." # https://curl.haxx.se/mail/archive-2008-07/0098.html # https://github.com/KrauseFx/xcode-install/issues/210 - retry_download_count.times do + number_of_try.times do # Non-blocking call of Open3 # We're not using the block based syntax, as the bacon testing # library doesn't seem to support writing tests for it @@ -100,7 +98,9 @@ def fetch(url: nil, end # Call back the block for other processes that might be interested + puts "progress_content: #{progress_content}" matched = progress_content.match(/^\s*(\d+)/) + puts "matched: #{matched}" next unless matched && matched.length == 2 percent = matched[1].to_i progress_block.call(percent) if progress_block @@ -137,7 +137,7 @@ def current_symlink File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil end - def download(version, progress, url = nil, progress_block = nil, retry_download_count = 3) + def download(version, progress, url = nil, progress_block = nil, number_of_try = 3) xcode = find_xcode_version(version) if url.nil? return if url.nil? && xcode.nil? @@ -150,7 +150,7 @@ def download(version, progress, url = nil, progress_block = nil, retry_download_ output: dmg_file, progress: progress, progress_block: progress_block, - retry_download_count: retry_download_count + number_of_try: number_of_try ) result ? CACHE_DIR + dmg_file : nil end @@ -283,8 +283,8 @@ def install_dmg(dmg_path, suffix = '', switch = true, clean = true) end # rubocop:disable Metrics/ParameterLists - def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, retry_download_count = 3) - dmg_path = get_dmg(version, progress, url, progress_block, retry_download_count) + def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try = 3) + dmg_path = get_dmg(version, progress, url, progress_block, number_of_try) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? if install @@ -373,7 +373,7 @@ def enable_developer_mode `sudo /usr/sbin/dseditgroup -o edit -t group -a staff _developer` end - def get_dmg(version, progress = true, url = nil, progress_block = nil, retry_download_count = 3) + def get_dmg(version, progress = true, url = nil, progress_block = nil, number_of_try = 3) if url path = Pathname.new(url) return path if path.exist? @@ -384,7 +384,7 @@ def get_dmg(version, progress = true, url = nil, progress_block = nil, retry_dow end end - download(version, progress, url, progress_block, retry_download_count) + download(version, progress, url, progress_block, number_of_try) end def fetch_seedlist @@ -515,13 +515,13 @@ def xcode end end - def download(progress, progress_block = nil, retry_download_count = 3) + def download(progress, progress_block = nil, number_of_try = 3) result = Curl.new.fetch( url: source, directory: CACHE_DIR, progress: progress, progress_block: progress_block, - retry_download_count: retry_download_count + number_of_try: number_of_try ) result ? dmg_path : nil end diff --git a/lib/xcode/install/install.rb b/lib/xcode/install/install.rb index c2926e4f..4b26aa4e 100644 --- a/lib/xcode/install/install.rb +++ b/lib/xcode/install/install.rb @@ -18,7 +18,7 @@ def self.options ['--no-progress', 'Don’t show download progress.'], ['--no-clean', 'Don’t delete DMG after installation.'], ['--no-show-release-notes', 'Don’t open release notes in browser after installation.'], - ['--retry-download-count', 'Count of retrying download when curl is failed.']].concat(super) + ['--number-of-try', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) end def initialize(argv) @@ -32,7 +32,7 @@ def initialize(argv) @should_switch = argv.flag?('switch', true) @progress = argv.flag?('progress', true) @show_release_notes = argv.flag?('show-release-notes', true) - @retry_download_count = argv.option('retry-download-count', '3') + @number_of_try = argv.option('number-of-try', '3') super end @@ -46,12 +46,12 @@ def validate! end fail Informative, "Version #{@version} doesn't exist." unless @url || @installer.exist?(@version) fail Informative, "Invalid URL: `#{@url}`" unless !@url || @url =~ /\A#{URI.regexp}\z/ - fail Informative, "Invalid Retry: `#{@retry_download_count} is not positive number.`" if (@retry_download_count =~ /\A[0-9]*\z/).nil? + fail Informative, "Invalid Retry: `#{@number_of_try} is not positive number.`" if (@number_of_try =~ /\A[0-9]*\z/).nil? end def run @installer.install_version(@version, @should_switch, @should_clean, @should_install, - @progress, @url, @show_release_notes, nil, @retry_download_count.to_i) + @progress, @url, @show_release_notes, nil, @number_of_try.to_i) end end end diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index 9df73484..83dd7704 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -11,7 +11,7 @@ def self.options ['--force', 'Install even if the same version is already installed.'], ['--no-install', 'Only download DMG, but do not install it.'], ['--no-progress', 'Don’t show download progress.'], - ['--retry-download-count', 'Count of retrying download when the curl operation fails.']].concat(super) + ['--number-of-try', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) end def initialize(argv) @@ -20,7 +20,7 @@ def initialize(argv) @force = argv.flag?('force', false) @should_install = argv.flag?('install', true) @progress = argv.flag?('progress', true) - @retry_download_count = argv.option('retry-download-count', '3') + @number_of_try = argv.option('number-of-try', '3') super end @@ -44,8 +44,8 @@ def install simulator = filtered_simulators.first fail Informative, "#{simulator.name} is already installed." if simulator.installed? && !@force puts "Installing #{simulator.name} for Xcode #{simulator.xcode.bundle_version}..." - fail Informative, "Invalid Retry: `#{@retry_download_count} is not positive number.`" if (@retry_download_count =~ /\A[0-9]*\z/).nil? - simulator.install(@progress, @should_install, @retry_download_count.to_i) + fail Informative, "Invalid Retry: `#{@number_of_try} is not positive number.`" if (@number_of_try =~ /\A[0-9]*\z/).nil? + simulator.install(@progress, @should_install, @number_of_try.to_i) else puts "[!] More than one simulator matching #{@install} was found. Please specify the full version.".ansi.red filtered_simulators.each do |candidate| From a44cd4981978410b3323d53225e1f4299ffec82e Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 14 Sep 2020 23:46:09 +0300 Subject: [PATCH 05/19] change option name to number-of-try --- lib/xcode/install.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 34fe5c7b..29842e1d 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -25,7 +25,7 @@ class Curl # @param progress: parse and show the progress? # @param progress_block: A block that's called whenever we have an updated progress % # the parameter is a single number that's literally percent (e.g. 1, 50, 80 or 100) - # @param number_of_try: A count to retry the downloading Xcode dmg/xip + # @param number_of_try: How many times try to download DMG file if downloading fails. Default is 3. # rubocop:disable Metrics/AbcSize def fetch(url: nil, directory: nil, @@ -98,9 +98,7 @@ def fetch(url: nil, end # Call back the block for other processes that might be interested - puts "progress_content: #{progress_content}" matched = progress_content.match(/^\s*(\d+)/) - puts "matched: #{matched}" next unless matched && matched.length == 2 percent = matched[1].to_i progress_block.call(percent) if progress_block From 0416bc1354881d740f74f4f526ec441558fe22b5 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 14 Sep 2020 23:57:46 +0300 Subject: [PATCH 06/19] change option name to number-of-try --- lib/xcode/install.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 29842e1d..3297202d 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -33,10 +33,11 @@ def fetch(url: nil, output: nil, progress: nil, progress_block: nil, - number_of_try: 3) + number_of_try: nil) options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] uri = URI.parse(url) + output ||= File.basename(uri.path) output = (Pathname.new(directory) + Pathname.new(output)) if directory @@ -281,7 +282,7 @@ def install_dmg(dmg_path, suffix = '', switch = true, clean = true) end # rubocop:disable Metrics/ParameterLists - def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try = 3) + def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try) dmg_path = get_dmg(version, progress, url, progress_block, number_of_try) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? @@ -513,7 +514,7 @@ def xcode end end - def download(progress, progress_block = nil, number_of_try = 3) + def download(progress, progress_block = nil, number_of_try) result = Curl.new.fetch( url: source, directory: CACHE_DIR, @@ -524,8 +525,8 @@ def download(progress, progress_block = nil, number_of_try = 3) result ? dmg_path : nil end - def install(progress, should_install) - dmg_path = download(progress) + def install(progress, should_install, number_of_try) + dmg_path = download(progress, number_of_try) fail Informative, "Failed to download #{@name}." if dmg_path.nil? return unless should_install @@ -779,4 +780,4 @@ def self.new_prerelease(version, url, release_notes_path) 'release_notes_path' => release_notes_path) end end -end +end \ No newline at end of file From 094549d41923fd4b407ceb5fdab90dfa7cffc790 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 15 Sep 2020 09:29:11 +0300 Subject: [PATCH 07/19] change initial value of number_of_try --- lib/xcode/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 3297202d..7653fbec 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -33,7 +33,7 @@ def fetch(url: nil, output: nil, progress: nil, progress_block: nil, - number_of_try: nil) + number_of_try: 3) options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] uri = URI.parse(url) From 1e19ac427c694f10fecbfb5f97bd5d1745e58658 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 15 Sep 2020 10:24:46 +0300 Subject: [PATCH 08/19] rubocop auto-fixes --- lib/xcode/install.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 7653fbec..484069d8 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -26,7 +26,6 @@ class Curl # @param progress_block: A block that's called whenever we have an updated progress % # the parameter is a single number that's literally percent (e.g. 1, 50, 80 or 100) # @param number_of_try: How many times try to download DMG file if downloading fails. Default is 3. - # rubocop:disable Metrics/AbcSize def fetch(url: nil, directory: nil, cookies: nil, @@ -37,7 +36,7 @@ def fetch(url: nil, options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] uri = URI.parse(url) - + output ||= File.basename(uri.path) output = (Pathname.new(directory) + Pathname.new(output)) if directory @@ -780,4 +779,4 @@ def self.new_prerelease(version, url, release_notes_path) 'release_notes_path' => release_notes_path) end end -end \ No newline at end of file +end From 323dff9d3d25b28e3a84f7d9821e5a298449ce4b Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 15 Sep 2020 12:10:17 +0300 Subject: [PATCH 09/19] fixed rubocop offenses --- lib/xcode/install.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 484069d8..57e6e0a8 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -281,7 +281,7 @@ def install_dmg(dmg_path, suffix = '', switch = true, clean = true) end # rubocop:disable Metrics/ParameterLists - def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try) + def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try = 3) dmg_path = get_dmg(version, progress, url, progress_block, number_of_try) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? @@ -513,7 +513,7 @@ def xcode end end - def download(progress, progress_block = nil, number_of_try) + def download(progress, progress_block = nil, number_of_try = 3) result = Curl.new.fetch( url: source, directory: CACHE_DIR, @@ -525,7 +525,7 @@ def download(progress, progress_block = nil, number_of_try) end def install(progress, should_install, number_of_try) - dmg_path = download(progress, number_of_try) + dmg_path = download(progress, nil, number_of_try) fail Informative, "Failed to download #{@name}." if dmg_path.nil? return unless should_install From fdc2749a805c58afecad5d43de9235fcbb26201b Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 5 Oct 2020 21:12:47 +0300 Subject: [PATCH 10/19] rename parameter --- lib/xcode/install/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install/install.rb b/lib/xcode/install/install.rb index 4b26aa4e..8c3920f9 100644 --- a/lib/xcode/install/install.rb +++ b/lib/xcode/install/install.rb @@ -18,7 +18,7 @@ def self.options ['--no-progress', 'Don’t show download progress.'], ['--no-clean', 'Don’t delete DMG after installation.'], ['--no-show-release-notes', 'Don’t open release notes in browser after installation.'], - ['--number-of-try', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) + ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) end def initialize(argv) From c14e5d2a68fef73ab02ca3e226f7522c3420b008 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Mon, 5 Oct 2020 21:15:00 +0300 Subject: [PATCH 11/19] rename parameter --- lib/xcode/install/simulators.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index 83dd7704..5ddf1419 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -11,7 +11,7 @@ def self.options ['--force', 'Install even if the same version is already installed.'], ['--no-install', 'Only download DMG, but do not install it.'], ['--no-progress', 'Don’t show download progress.'], - ['--number-of-try', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) + ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) end def initialize(argv) From 63908473794d652f63e115001093dc724e91efea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Mon, 5 Oct 2020 23:23:23 +0300 Subject: [PATCH 12/19] Update lib/xcode/install/simulators.rb Co-authored-by: Josh Holtz --- lib/xcode/install/simulators.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index 5ddf1419..fb979440 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -20,7 +20,7 @@ def initialize(argv) @force = argv.flag?('force', false) @should_install = argv.flag?('install', true) @progress = argv.flag?('progress', true) - @number_of_try = argv.option('number-of-try', '3') + @number_of_try = argv.option('retry-count', '3') super end From d77e6b8a98370f32d8208213ba1b57388a8d5b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Mon, 5 Oct 2020 23:23:34 +0300 Subject: [PATCH 13/19] Update lib/xcode/install/install.rb Co-authored-by: Josh Holtz --- lib/xcode/install/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install/install.rb b/lib/xcode/install/install.rb index 8c3920f9..a74e07e9 100644 --- a/lib/xcode/install/install.rb +++ b/lib/xcode/install/install.rb @@ -32,7 +32,7 @@ def initialize(argv) @should_switch = argv.flag?('switch', true) @progress = argv.flag?('progress', true) @show_release_notes = argv.flag?('show-release-notes', true) - @number_of_try = argv.option('number-of-try', '3') + @number_of_try = argv.option('retry-count', '3') super end From 65d6900c5b6c66aef6143b80047bc2e3689da9a3 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 6 Oct 2020 15:06:27 +0300 Subject: [PATCH 14/19] readding the retry_options --- lib/xcode/install.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 57e6e0a8..99bf2a0d 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -58,11 +58,13 @@ def fetch(url: nil, # wait for the process to be finished progress_log_file = File.join(CACHE_DIR, "progress.#{Time.now.to_i}.progress") FileUtils.rm_f(progress_log_file) - + + retry_options = ['--retry', number_of_try] command = [ 'curl', '--disable', *options, + *retry_options, '--location', '--continue-at', '-', From 604d308501c41ced5237ba5d4eea7a4e3db04284 Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 6 Oct 2020 16:02:13 +0300 Subject: [PATCH 15/19] rubocup fix --- lib/xcode/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 99bf2a0d..b84bb610 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -58,7 +58,7 @@ def fetch(url: nil, # wait for the process to be finished progress_log_file = File.join(CACHE_DIR, "progress.#{Time.now.to_i}.progress") FileUtils.rm_f(progress_log_file) - + retry_options = ['--retry', number_of_try] command = [ 'curl', From 0909d8041ff681826fea2dc7e077bc22ac3e1e4f Mon Sep 17 00:00:00 2001 From: gunesmes Date: Tue, 6 Oct 2020 18:03:12 +0300 Subject: [PATCH 16/19] rubocup fix Assignment Branch Condition --- lib/xcode/install.rb | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index b84bb610..ce82dc60 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -26,6 +26,51 @@ class Curl # @param progress_block: A block that's called whenever we have an updated progress % # the parameter is a single number that's literally percent (e.g. 1, 50, 80 or 100) # @param number_of_try: How many times try to download DMG file if downloading fails. Default is 3. + def curl_file(command_string, + progress, + progress_block, + progress_log_file, + number_of_try) + # Run the curl command in a loop, retry when curl exit status is 18 + # "Partial file. Only a part of the file was transferred." + # https://curl.haxx.se/mail/archive-2008-07/0098.html + # https://github.com/KrauseFx/xcode-install/issues/210 + number_of_try.times do + # Non-blocking call of Open3 + # We're not using the block based syntax, as the bacon testing + # library doesn't seem to support writing tests for it + stdin, stdout, stderr, wait_thr = Open3.popen3(command_string) + + # Poll the file and see if we're done yet + while wait_thr.alive? + sleep(0.5) # it's not critical for this to be real-time + next unless File.exist?(progress_log_file) # it might take longer for it to be created + + progress_content = File.read(progress_log_file).split("\r").last + + # Print out the progress for the CLI + if progress + print "\r#{progress_content}%" + $stdout.flush + end + + # Call back the block for other processes that might be interested + matched = progress_content.match(/^\s*(\d+)/) + next unless matched && matched.length == 2 + percent = matched[1].to_i + progress_block.call(percent) if progress_block + end + + # as we're not making use of the block-based syntax + # we need to manually close those + stdin.close + stdout.close + stderr.close + + return wait_thr.value.success? if wait_thr.value.success? + end + end + def fetch(url: nil, directory: nil, cookies: nil, @@ -76,44 +121,7 @@ def fetch(url: nil, command_string = command.collect(&:shellescape).join(' ') command_string += " 2> #{progress_log_file}" # to not run shellescape on the `2>` - # Run the curl command in a loop, retry when curl exit status is 18 - # "Partial file. Only a part of the file was transferred." - # https://curl.haxx.se/mail/archive-2008-07/0098.html - # https://github.com/KrauseFx/xcode-install/issues/210 - number_of_try.times do - # Non-blocking call of Open3 - # We're not using the block based syntax, as the bacon testing - # library doesn't seem to support writing tests for it - stdin, stdout, stderr, wait_thr = Open3.popen3(command_string) - - # Poll the file and see if we're done yet - while wait_thr.alive? - sleep(0.5) # it's not critical for this to be real-time - next unless File.exist?(progress_log_file) # it might take longer for it to be created - - progress_content = File.read(progress_log_file).split("\r").last - - # Print out the progress for the CLI - if progress - print "\r#{progress_content}%" - $stdout.flush - end - - # Call back the block for other processes that might be interested - matched = progress_content.match(/^\s*(\d+)/) - next unless matched && matched.length == 2 - percent = matched[1].to_i - progress_block.call(percent) if progress_block - end - - # as we're not making use of the block-based syntax - # we need to manually close those - stdin.close - stdout.close - stderr.close - - return wait_thr.value.success? if wait_thr.value.success? - end + curl_file(command_string, progress, progress_block, progress_log_file, number_of_try) false ensure FileUtils.rm_f(COOKIES_PATH) From 3c920303726dfa1c1b1abddc1cfd9d1804578120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Sat, 22 May 2021 19:31:02 +0300 Subject: [PATCH 17/19] update default number of trial to 10 --- lib/xcode/install.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 9caea010..a627b93d 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -25,7 +25,7 @@ class Curl # @param progress: parse and show the progress? # @param progress_block: A block that's called whenever we have an updated progress % # the parameter is a single number that's literally percent (e.g. 1, 50, 80 or 100) - # @param number_of_try: How many times try to download DMG file if downloading fails. Default is 3. + # @param number_of_try: How many times try to download DMG file if downloading fails. Default is 10. def curl_file(command_string, progress, progress_block, @@ -78,7 +78,7 @@ def fetch(url: nil, output: nil, progress: nil, progress_block: nil, - number_of_try: 3) + number_of_try: 10) options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] uri = URI.parse(url) @@ -189,7 +189,7 @@ def current_symlink File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil end - def download(version, progress, url = nil, progress_block = nil, number_of_try = 3) + def download(version, progress, url = nil, progress_block = nil, number_of_try = 10) xcode = find_xcode_version(version) if url.nil? return if url.nil? && xcode.nil? @@ -335,7 +335,7 @@ def install_dmg(dmg_path, suffix = '', switch = true, clean = true) end # rubocop:disable Metrics/ParameterLists - def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try = 3) + def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil, show_release_notes = true, progress_block = nil, number_of_try = 10) dmg_path = get_dmg(version, progress, url, progress_block, number_of_try) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? @@ -425,7 +425,7 @@ def enable_developer_mode `sudo /usr/sbin/dseditgroup -o edit -t group -a staff _developer` end - def get_dmg(version, progress = true, url = nil, progress_block = nil, number_of_try = 3) + def get_dmg(version, progress = true, url = nil, progress_block = nil, number_of_try = 10) if url path = Pathname.new(url) return path if path.exist? @@ -596,7 +596,7 @@ def xcode end end - def download(progress, progress_block = nil, number_of_try = 3) + def download(progress, progress_block = nil, number_of_try = 10) result = Curl.new.fetch( url: source, directory: CACHE_DIR, From e27710ae5eefbd5f47bbbf906c965efe02dccafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Sat, 22 May 2021 19:36:27 +0300 Subject: [PATCH 18/19] update default retrial count to 10 --- lib/xcode/install/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xcode/install/install.rb b/lib/xcode/install/install.rb index b4031d66..f7e0b806 100644 --- a/lib/xcode/install/install.rb +++ b/lib/xcode/install/install.rb @@ -18,7 +18,7 @@ def self.options ['--no-progress', 'Don’t show download progress.'], ['--no-clean', 'Don’t delete DMG after installation.'], ['--no-show-release-notes', 'Don’t open release notes in browser after installation.'], - ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) + ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 10.']].concat(super) end def initialize(argv) @@ -32,7 +32,7 @@ def initialize(argv) @should_switch = argv.flag?('switch', true) @progress = argv.flag?('progress', true) @show_release_notes = argv.flag?('show-release-notes', true) - @number_of_try = argv.option('retry-count', '3') + @number_of_try = argv.option('retry-count', '10') super end From 3062bd200140f3e34bbe0c699c922b2777928795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mesut=20G=C3=BCne=C5=9F?= Date: Sat, 22 May 2021 19:38:03 +0300 Subject: [PATCH 19/19] update retrial count to 10 --- lib/xcode/install/simulators.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xcode/install/simulators.rb b/lib/xcode/install/simulators.rb index fb979440..5ace57c3 100644 --- a/lib/xcode/install/simulators.rb +++ b/lib/xcode/install/simulators.rb @@ -11,7 +11,7 @@ def self.options ['--force', 'Install even if the same version is already installed.'], ['--no-install', 'Only download DMG, but do not install it.'], ['--no-progress', 'Don’t show download progress.'], - ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 3.']].concat(super) + ['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 10.']].concat(super) end def initialize(argv) @@ -20,7 +20,7 @@ def initialize(argv) @force = argv.flag?('force', false) @should_install = argv.flag?('install', true) @progress = argv.flag?('progress', true) - @number_of_try = argv.option('retry-count', '3') + @number_of_try = argv.option('retry-count', '10') super end