From 7f45c634681330ab32d9d069d6af131283695664 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 1 Mar 2014 12:28:45 +0000 Subject: fetch: add --retry option to retry fetch once. Sometimes there may be intermittent failures with hosts that work if immediately retried. Let's allow a single retry in this case with the --retry flag. This also behaves nicely with the --force flag. Signed-off-by: Mike McQuaid --- Library/Homebrew/cmd/fetch.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 1fcc5b28e..0a59c6540 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -28,19 +28,33 @@ module Homebrew extend self puts "Resource: #{r.name}" fetch_fetchable r rescue ChecksumMismatchError => e - Homebrew.failed = true + retry if retry_fetch? f opoo "Resource #{r.name} reports different #{e.hash_type}: #{e.expected}" end def fetch_formula f fetch_fetchable f rescue ChecksumMismatchError => e - Homebrew.failed = true + retry if retry_fetch? f opoo "Formula reports different #{e.hash_type}: #{e.expected}" end private + def retry_fetch? f + @failed ||= {} + already_failed = @failed.fetch(f.name, false) + + if already_failed || !ARGV.include?("--retry") + Homebrew.failed = true + return false + end + + f.clear_cache + @failed[f.name] = true + true + end + def fetch_fetchable f f.clear_cache if ARGV.force? -- cgit v1.2.3