Reorganize methods in CurlDownloadStrategy

This commit is contained in:
Jack Nagel 2014-12-10 00:53:57 -05:00
parent 00ad37dd84
commit 37c636ae18

View File

@ -159,23 +159,6 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
@temporary_path = Pathname.new("#{tarball_path}.incomplete") @temporary_path = Pathname.new("#{tarball_path}.incomplete")
end end
def cached_location
tarball_path
end
def clear_cache
[cached_location, temporary_path].each { |f| f.unlink if f.exist? }
end
def downloaded_size
temporary_path.size? or 0
end
# Private method, can be overridden if needed.
def _fetch
curl @url, '-C', downloaded_size, '-o', temporary_path
end
def fetch def fetch
ohai "Downloading #{@url}" ohai "Downloading #{@url}"
unless tarball_path.exist? unless tarball_path.exist?
@ -210,20 +193,6 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
retry retry
end end
# gunzip and bunzip2 write the output file in the same directory as the input
# file regardless of the current working directory, so we need to write it to
# the correct location ourselves.
def buffered_write(tool)
target = File.basename(basename_without_params, tarball_path.extname)
Utils.popen_read(tool, "-f", tarball_path.to_s, "-c") do |pipe|
File.open(target, "wb") do |f|
buf = ""
f.write(buf) while pipe.read(1024, buf)
end
end
end
def stage def stage
case tarball_path.compression_type case tarball_path.compression_type
when :zip when :zip
@ -254,8 +223,25 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
end end
end end
def cached_location
tarball_path
end
def clear_cache
[cached_location, temporary_path].each { |f| f.unlink if f.exist? }
end
private private
# Private method, can be overridden if needed.
def _fetch
curl @url, "-C", downloaded_size, "-o", temporary_path
end
def downloaded_size
temporary_path.size? || 0
end
def curl(*args) def curl(*args)
args << '--connect-timeout' << '5' unless mirrors.empty? args << '--connect-timeout' << '5' unless mirrors.empty?
args << "--user" << meta.fetch(:user) if meta.key?(:user) args << "--user" << meta.fetch(:user) if meta.key?(:user)
@ -270,6 +256,20 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
end end
end end
# gunzip and bunzip2 write the output file in the same directory as the input
# file regardless of the current working directory, so we need to write it to
# the correct location ourselves.
def buffered_write(tool)
target = File.basename(basename_without_params, tarball_path.extname)
Utils.popen_read(tool, "-f", tarball_path.to_s, "-c") do |pipe|
File.open(target, "wb") do |f|
buf = ""
f.write(buf) while pipe.read(1024, buf)
end
end
end
def basename_without_params def basename_without_params
# Strip any ?thing=wad out of .c?thing=wad style extensions # Strip any ?thing=wad out of .c?thing=wad style extensions
File.basename(@url)[/[^?]+/] File.basename(@url)[/[^?]+/]