Reorganize methods in CurlDownloadStrategy
This commit is contained in:
parent
00ad37dd84
commit
37c636ae18
@ -159,23 +159,6 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
||||
@temporary_path = Pathname.new("#{tarball_path}.incomplete")
|
||||
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
|
||||
ohai "Downloading #{@url}"
|
||||
unless tarball_path.exist?
|
||||
@ -210,20 +193,6 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
||||
retry
|
||||
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
|
||||
case tarball_path.compression_type
|
||||
when :zip
|
||||
@ -254,8 +223,25 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
||||
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 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)
|
||||
args << '--connect-timeout' << '5' unless mirrors.empty?
|
||||
args << "--user" << meta.fetch(:user) if meta.key?(:user)
|
||||
@ -270,6 +256,20 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
||||
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
|
||||
# Strip any ?thing=wad out of .c?thing=wad style extensions
|
||||
File.basename(@url)[/[^?]+/]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user