Extract common decompression code to a method
This commit is contained in:
parent
cb5da28b5c
commit
7541f13164
@ -138,36 +138,29 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
|||||||
tarball_path
|
tarball_path
|
||||||
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)
|
||||||
|
|
||||||
|
IO.popen("#{tool} -f '#{tarball_path}' -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
|
||||||
with_system_path { quiet_safe_system 'unzip', {:quiet_flag => '-qq'}, tarball_path }
|
with_system_path { quiet_safe_system 'unzip', {:quiet_flag => '-qq'}, tarball_path }
|
||||||
chdir
|
chdir
|
||||||
when :gzip_only
|
when :gzip_only
|
||||||
# gunzip writes the compressed data in the location of the original,
|
with_system_path { buffered_write("gunzip") }
|
||||||
# regardless of the current working directory; the only way to
|
|
||||||
# write elsewhere is to use the stdout
|
|
||||||
with_system_path do
|
|
||||||
target = File.basename(basename_without_params, ".gz")
|
|
||||||
|
|
||||||
IO.popen("gunzip -f '#{tarball_path}' -c") do |pipe|
|
|
||||||
File.open(target, "wb") do |f|
|
|
||||||
buf = ""
|
|
||||||
f.write(buf) while pipe.read(1024, buf)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when :bzip2_only
|
when :bzip2_only
|
||||||
with_system_path do
|
with_system_path { buffered_write("bunzip2") }
|
||||||
target = File.basename(basename_without_params, ".bz2")
|
|
||||||
|
|
||||||
IO.popen("bunzip2 -f '#{tarball_path}' -c") do |pipe|
|
|
||||||
File.open(target, "wb") do |f|
|
|
||||||
buf = ""
|
|
||||||
f.write(buf) while pipe.read(1024, buf)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when :gzip, :bzip2, :compress, :tar
|
when :gzip, :bzip2, :compress, :tar
|
||||||
# Assume these are also tarred
|
# Assume these are also tarred
|
||||||
# TODO check if it's really a tar archive
|
# TODO check if it's really a tar archive
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user