Added support for returning HTTP status codes and for git and svn URLs

This commit is contained in:
David Broder-Rodgers 2016-12-10 14:20:47 +00:00
parent ea440ca328
commit ed9f775b77
4 changed files with 31 additions and 4 deletions

View File

@ -1490,10 +1490,20 @@ class ResourceAuditor
return unless @online
urls.each do |url|
begin
nostdout { curl "--connect-timeout", "15", "--output", "/dev/null", "--range", "0-0", url }
rescue ErrorDuringExecution
problem "The mirror #{url} is not reachable (curl exit code #{$?.exitstatus})"
if url.start_with? "http", "ftp"
status_code, _, _ = curl_output "--connect-timeout", "15", "--output", "/dev/null", "--range", "0-0", \
"--write-out", "%{http_code}", url
unless status_code.start_with? "20"
problem "The mirror #{url} is not reachable (HTTP status code #{status_code})"
end
elsif url.start_with? "git"
unless Utils.git_remote_exists url
problem "The mirror #{url} is not a valid git URL"
end
elsif url.start_with? "svn"
unless Utils.svn_remote_exists url
problem "The mirror #{url} is not a valid svn URL"
end
end
check_insecure_mirror(url) if url.start_with? "http:"
end

View File

@ -10,6 +10,7 @@ require "utils/github"
require "utils/hash"
require "utils/inreplace"
require "utils/popen"
require "utils/svn"
require "utils/tty"
require "time"

View File

@ -40,4 +40,9 @@ module Utils
@git_path = nil
@git_version = nil
end
def self.git_remote_exists(url)
return true unless git_available?
quiet_system "git", "ls-remote", url
end
end

View File

@ -0,0 +1,11 @@
module Utils
def self.svn_available?
return @svn if instance_variable_defined?(:@svn)
@svn = quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version"
end
def self.svn_remote_exists(url)
return true unless svn_available?
quiet_system "svn", "ls", url, "--depth", "empty"
end
end