diff options
Diffstat (limited to 'Library/Homebrew/download_strategy.rb')
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2ee9bcc1a..5243a7536 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -1,11 +1,11 @@ -require 'utils/json' +require "utils/json" class AbstractDownloadStrategy include FileUtils attr_reader :meta, :name, :version, :resource - def initialize name, resource + def initialize(name, resource) @name = name @resource = resource @url = resource.url @@ -32,7 +32,7 @@ class AbstractDownloadStrategy rm_rf(cached_location) end - def expand_safe_system_args args + def expand_safe_system_args(args) args = args.dup args.each_with_index do |arg, ii| if arg.is_a? Hash @@ -45,11 +45,11 @@ class AbstractDownloadStrategy end end # 2 as default because commands are eg. svn up, git pull - args.insert(2, '-q') unless ARGV.verbose? + args.insert(2, "-q") unless ARGV.verbose? args end - def quiet_safe_system *args + def quiet_safe_system(*args) safe_system(*expand_safe_system_args(args)) end @@ -73,7 +73,7 @@ class AbstractDownloadStrategy #{HOMEBREW_PREFIX}/bin/cvs #{HOMEBREW_PREFIX}/opt/cvs/bin/cvs #{which("cvs")} - ].find { |p| File.executable? p } + ].find { |p| File.executable? p } end def hgpath @@ -81,7 +81,7 @@ class AbstractDownloadStrategy #{which("hg")} #{HOMEBREW_PREFIX}/bin/hg #{HOMEBREW_PREFIX}/opt/mercurial/bin/hg - ].find { |p| File.executable? p } + ].find { |p| File.executable? p } end def bzrpath @@ -89,7 +89,7 @@ class AbstractDownloadStrategy #{which("bzr")} #{HOMEBREW_PREFIX}/bin/bzr #{HOMEBREW_PREFIX}/opt/bazaar/bin/bzr - ].find { |p| File.executable? p } + ].find { |p| File.executable? p } end def fossilpath @@ -97,14 +97,14 @@ class AbstractDownloadStrategy #{which("fossil")} #{HOMEBREW_PREFIX}/bin/fossil #{HOMEBREW_PREFIX}/opt/fossil/bin/fossil - ].find { |p| File.executable? p } + ].find { |p| File.executable? p } end end class VCSDownloadStrategy < AbstractDownloadStrategy REF_TYPES = [:tag, :branch, :revisions, :revision].freeze - def initialize name, resource + def initialize(name, resource) super @ref_type, @ref = extract_ref(meta) @revision = meta[:revision] @@ -172,7 +172,7 @@ class VCSDownloadStrategy < AbstractDownloadStrategy def extract_ref(specs) key = REF_TYPES.find { |type| specs.key?(type) } - return key, specs[key] + [key, specs[key]] end end @@ -180,7 +180,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy def stage case cached_location.compression_type when :zip - with_system_path { quiet_safe_system 'unzip', {:quiet_flag => '-qq'}, cached_location } + with_system_path { quiet_safe_system "unzip", { :quiet_flag => "-qq" }, cached_location } chdir when :gzip_only with_system_path { buffered_write("gunzip") } @@ -188,7 +188,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy with_system_path { buffered_write("bunzip2") } when :gzip, :bzip2, :compress, :tar # Assume these are also tarred - with_system_path { safe_system 'tar', 'xf', cached_location } + with_system_path { safe_system "tar", "xf", cached_location } chdir when :xz with_system_path { pipe_to_tar(xzpath) } @@ -201,9 +201,9 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy when :xar safe_system "/usr/bin/xar", "-xf", cached_location when :rar - quiet_safe_system 'unrar', 'x', {:quiet_flag => '-inul'}, cached_location + quiet_safe_system "unrar", "x", { :quiet_flag => "-inul" }, cached_location when :p7zip - safe_system '7zr', 'x', cached_location + safe_system "7zr", "x", cached_location else cp cached_location, basename_without_params end @@ -212,7 +212,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy private def chdir - entries = Dir['*'] + entries = Dir["*"] case entries.length when 0 then raise "Empty archive" when 1 then Dir.chdir entries.first rescue nil @@ -275,7 +275,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy unless urls.empty? ohai "Downloading from #{urls.last}" if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && @url.start_with?("https://") && - urls.any? { |u| !u.start_with? "https://" } + urls.any? { |u| !u.start_with? "https://" } raise "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." end @url = urls.last @@ -346,7 +346,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy def curl(*args) args.concat _curl_opts - args << '--connect-timeout' << '5' unless mirrors.empty? + args << "--connect-timeout" << "5" unless mirrors.empty? super end end @@ -378,7 +378,7 @@ class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy mirrors = Utils::JSON.load(apache_mirrors) path_info = mirrors.fetch("path_info") - @url = mirrors.fetch('preferred') + path_info + @url = mirrors.fetch("preferred") + path_info @mirrors |= %W[https://archive.apache.org/dist/#{path_info}] ohai "Best Mirror #{@url}" @@ -392,8 +392,8 @@ end # Query parameters on the URL are converted into POST parameters class CurlPostDownloadStrategy < CurlDownloadStrategy def _fetch - base_url,data = @url.split('?') - curl base_url, '-d', data, '-C', downloaded_size, '-o', temporary_path + base_url, data = @url.split("?") + curl base_url, "-d", data, "-C", downloaded_size, "-o", temporary_path end end @@ -438,20 +438,21 @@ class S3DownloadStrategy < CurlDownloadStrategy def _fetch # Put the aws gem requirement here (vs top of file) so it's only # a dependency of S3 users, not all Homebrew users - require 'rubygems' + require "rubygems" begin - require 'aws-sdk-v1' + require "aws-sdk-v1" rescue LoadError onoe "Install the aws-sdk gem into the gem repo used by brew." raise end - if @url !~ %r[^https?://+([^.]+).s3.amazonaws.com/+(.+)$] then + if @url !~ %r{^https?://+([^.]+).s3.amazonaws.com/+(.+)$} raise "Bad S3 URL: " + @url end - (bucket,key) = $1,$2 + bucket = $1 + key = $2 - obj = AWS::S3.new().buckets[bucket].objects[key] + obj = AWS::S3.new.buckets[bucket].objects[key] begin s3url = obj.url_for(:get) rescue AWS::Errors::MissingCredentialsError @@ -459,7 +460,7 @@ class S3DownloadStrategy < CurlDownloadStrategy s3url = obj.public_url end - curl s3url, '-C', downloaded_size, '-o', temporary_path + curl s3url, "-C", downloaded_size, "-o", temporary_path end end @@ -470,7 +471,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy end def fetch - clear_cache unless @url.chomp("/") == repo_url or quiet_system "svn", "switch", @url, cached_location + clear_cache unless @url.chomp("/") == repo_url || quiet_system("svn", "switch", @url, cached_location) super end @@ -492,16 +493,16 @@ class SubversionDownloadStrategy < VCSDownloadStrategy end end - def fetch_repo target, url, revision=nil, ignore_externals=false + def fetch_repo(target, url, revision = nil, ignore_externals = false) # Use "svn up" when the repository already exists locally. # This saves on bandwidth and will have a similar effect to verifying the # cache as it will make any changes to get the right revision. - svncommand = target.directory? ? 'up' : 'checkout' - args = ['svn', svncommand] + svncommand = target.directory? ? "up" : "checkout" + args = ["svn", svncommand] args << url unless target.directory? args << target - args << '-r' << revision if revision - args << '--ignore-externals' if ignore_externals + args << "-r" << revision if revision + args << "--ignore-externals" if ignore_externals quiet_safe_system(*args) end @@ -537,10 +538,10 @@ class GitDownloadStrategy < VCSDownloadStrategy %r{git://}, %r{https://github\.com}, %r{http://git\.sv\.gnu\.org}, - %r{http://llvm\.org}, + %r{http://llvm\.org} ] - def initialize name, resource + def initialize(name, resource) super @ref_type ||= :branch @ref ||= "master" @@ -589,11 +590,11 @@ class GitDownloadStrategy < VCSDownloadStrategy end def has_ref? - quiet_system 'git', '--git-dir', git_dir, 'rev-parse', '-q', '--verify', "#{@ref}^{commit}" + quiet_system "git", "--git-dir", git_dir, "rev-parse", "-q", "--verify", "#{@ref}^{commit}" end def current_revision - Utils.popen_read('git', '--git-dir', git_dir, 'rev-parse', '-q', '--verify', "HEAD").strip + Utils.popen_read("git", "--git-dir", git_dir, "rev-parse", "-q", "--verify", "HEAD").strip end def repo_valid? @@ -605,11 +606,11 @@ class GitDownloadStrategy < VCSDownloadStrategy end def clone_args - args = %w{clone} - args << '--depth' << '1' if shallow_clone? + args = %w[clone] + args << "--depth" << "1" if shallow_clone? case @ref_type - when :branch, :tag then args << '--branch' << @ref + when :branch, :tag then args << "--branch" << @ref end args << @url << cached_location @@ -617,29 +618,29 @@ class GitDownloadStrategy < VCSDownloadStrategy def refspec case @ref_type - when :branch then "+refs/heads/#@ref:refs/remotes/origin/#@ref" - when :tag then "+refs/tags/#@ref:refs/tags/#@ref" + when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}" + when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}" else "+refs/heads/master:refs/remotes/origin/master" end end def config_repo - safe_system 'git', 'config', 'remote.origin.url', @url - safe_system 'git', 'config', 'remote.origin.fetch', refspec + safe_system "git", "config", "remote.origin.url", @url + safe_system "git", "config", "remote.origin.fetch", refspec end def update_repo if @ref_type == :branch || !has_ref? if !shallow_clone? && is_shallow_clone? - quiet_safe_system 'git', 'fetch', 'origin', '--unshallow' + quiet_safe_system "git", "fetch", "origin", "--unshallow" else - quiet_safe_system 'git', 'fetch', 'origin' + quiet_safe_system "git", "fetch", "origin" end end end def clone_repo - safe_system 'git', *clone_args + safe_system "git", *clone_args cached_location.cd do safe_system "git", "config", "homebrew.cacheversion", cache_version update_submodules if submodules? @@ -652,15 +653,15 @@ class GitDownloadStrategy < VCSDownloadStrategy def reset_args ref = case @ref_type - when :branch then "origin/#@ref" + when :branch then "origin/#{@ref}" when :revision, :tag then @ref end - %W{reset --hard #{ref}} + %W[reset --hard #{ref}] end def reset - quiet_safe_system 'git', *reset_args + quiet_safe_system "git", *reset_args end def update_submodules @@ -672,11 +673,11 @@ end class CVSDownloadStrategy < VCSDownloadStrategy def initialize(name, resource) super - @url = @url.sub(%r[^cvs://], "") + @url = @url.sub(%r{^cvs://}, "") if meta.key?(:module) @module = meta.fetch(:module) - elsif @url !~ %r[:[^/]+$] + elsif @url !~ %r{:[^/]+$} @module = name else @module, @url = split_url(@url) @@ -712,15 +713,15 @@ class CVSDownloadStrategy < VCSDownloadStrategy def split_url(in_url) parts = in_url.split(/:/) mod=parts.pop - url=parts.join(':') - [ mod, url ] + url=parts.join(":") + [mod, url] end end class MercurialDownloadStrategy < VCSDownloadStrategy def initialize(name, resource) super - @url = @url.sub(%r[^hg://], "") + @url = @url.sub(%r{^hg://}, "") end def stage @@ -728,10 +729,10 @@ class MercurialDownloadStrategy < VCSDownloadStrategy dst = Dir.getwd cached_location.cd do - if @ref_type and @ref - safe_system hgpath, 'archive', '--subrepos', '-y', '-r', @ref, '-t', 'files', dst + if @ref_type && @ref + safe_system hgpath, "archive", "--subrepos", "-y", "-r", @ref, "-t", "files", dst else - safe_system hgpath, 'archive', '--subrepos', '-y', '-t', 'files', dst + safe_system hgpath, "archive", "--subrepos", "-y", "-t", "files", dst end end end @@ -758,7 +759,7 @@ end class BazaarDownloadStrategy < VCSDownloadStrategy def initialize(name, resource) super - @url = @url.sub(%r[^bzr://], "") + @url = @url.sub(%r{^bzr://}, "") end def stage @@ -791,7 +792,7 @@ end class FossilDownloadStrategy < VCSDownloadStrategy def initialize(name, resource) super - @url = @url.sub(%r[^fossil://], "") + @url = @url.sub(%r{^fossil://}, "") end def stage @@ -814,15 +815,14 @@ class FossilDownloadStrategy < VCSDownloadStrategy def update safe_system fossilpath, "pull", "-R", cached_location end - end class DownloadStrategyDetector - def self.detect(url, strategy=nil) + def self.detect(url, strategy = nil) if strategy.nil? detect_from_url(url) elsif Class === strategy && strategy < AbstractDownloadStrategy - strategy + strategy elsif Symbol === strategy detect_from_symbol(strategy) else @@ -833,25 +833,25 @@ class DownloadStrategyDetector def self.detect_from_url(url) case url - when %r[^https?://.+\.git$], %r[^git://] + when %r{^https?://.+\.git$}, %r{^git://} GitDownloadStrategy - when %r[^https?://www\.apache\.org/dyn/closer\.cgi] + when %r{^https?://www\.apache\.org/dyn/closer\.cgi} CurlApacheMirrorDownloadStrategy - when %r[^https?://(.+?\.)?googlecode\.com/svn], %r[^https?://svn\.], %r[^svn://], %r[^https?://(.+?\.)?sourceforge\.net/svnroot/] + when %r{^https?://(.+?\.)?googlecode\.com/svn}, %r{^https?://svn\.}, %r{^svn://}, %r{^https?://(.+?\.)?sourceforge\.net/svnroot/} SubversionDownloadStrategy - when %r[^cvs://] + when %r{^cvs://} CVSDownloadStrategy - when %r[^https?://(.+?\.)?googlecode\.com/hg] + when %r{^https?://(.+?\.)?googlecode\.com/hg} MercurialDownloadStrategy - when %r[^hg://] + when %r{^hg://} MercurialDownloadStrategy - when %r[^bzr://] + when %r{^bzr://} BazaarDownloadStrategy - when %r[^fossil://] + when %r{^fossil://} FossilDownloadStrategy - when %r[^http://svn\.apache\.org/repos/], %r[^svn\+http://] + when %r{^http://svn\.apache\.org/repos/}, %r{^svn\+http://} SubversionDownloadStrategy - when %r[^https?://(.+?\.)?sourceforge\.net/hgweb/] + when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/} MercurialDownloadStrategy else CurlDownloadStrategy |
