Merge pull request #4526 from reitermarkus/extract-verbose
Move `verbose` from `#initialize` to `#extract`.
This commit is contained in:
commit
a6dfe08c3c
@ -28,7 +28,7 @@ module Hbc
|
||||
end
|
||||
|
||||
ohai "Extracting nested container #{path.relative_path_from(cask.staged_path)}"
|
||||
container.new(cask, path, command, verbose: verbose).extract(to: cask.staged_path)
|
||||
container.new(cask, path, command).extract(to: cask.staged_path, verbose: verbose)
|
||||
FileUtils.remove_entry_secure(path)
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
path.extname == ".air"
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!(
|
||||
"/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer",
|
||||
args: ["-silent", "-location", unpack_dir, path],
|
||||
|
||||
@ -5,23 +5,20 @@ module Hbc
|
||||
|
||||
attr_reader :path
|
||||
|
||||
attr_predicate :verbose?
|
||||
|
||||
def initialize(cask, path, command, nested: false, verbose: false)
|
||||
def initialize(cask, path, command, nested: false)
|
||||
@cask = cask
|
||||
@path = path
|
||||
@command = command
|
||||
@verbose = verbose
|
||||
end
|
||||
|
||||
def extract(to: nil, basename: nil)
|
||||
def extract(to: nil, basename: nil, verbose: false)
|
||||
basename ||= path.basename
|
||||
unpack_dir = Pathname(to || Dir.pwd).expand_path
|
||||
unpack_dir.mkpath
|
||||
extract_to_dir(unpack_dir, basename: basename)
|
||||
extract_to_dir(unpack_dir, basename: basename, verbose: verbose)
|
||||
end
|
||||
|
||||
def extract_nested_inside(dir, to:)
|
||||
def extract_nested_inside(dir, to:, verbose: false)
|
||||
children = Pathname.new(dir).children
|
||||
|
||||
nested_container = children[0]
|
||||
@ -29,7 +26,7 @@ module Hbc
|
||||
unless children.count == 1 &&
|
||||
!nested_container.directory? &&
|
||||
@cask.artifacts.none? { |a| a.is_a?(Artifact::NestedContainer) } &&
|
||||
extract_nested_container(nested_container, to: to)
|
||||
extract_nested_container(nested_container, to: to, verbose: verbose)
|
||||
|
||||
children.each do |src|
|
||||
dest = @cask.staged_path.join(src.basename)
|
||||
@ -39,13 +36,13 @@ module Hbc
|
||||
end
|
||||
end
|
||||
|
||||
def extract_nested_container(source, to:)
|
||||
def extract_nested_container(source, to:, verbose: false)
|
||||
container = Container.for_path(source)
|
||||
|
||||
return false unless container
|
||||
|
||||
ohai "Extracting nested container #{source.basename}"
|
||||
container.new(@cask, source, @command, verbose: verbose?).extract(to: to)
|
||||
container.new(@cask, source, @command).extract(to: to, verbose: verbose)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\ABZh/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
Dir.mktmpdir do |tmp_unpack_dir|
|
||||
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\A(MSCF|MZ)/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("cabextract",
|
||||
args: ["-d", unpack_dir, "--", path],
|
||||
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) })
|
||||
|
||||
@ -14,7 +14,7 @@ module Hbc
|
||||
!imageinfo.empty?
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
mount do |mounts|
|
||||
begin
|
||||
raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad disk image?" if mounts.empty?
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
false
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("unar",
|
||||
args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", path],
|
||||
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) })
|
||||
|
||||
@ -23,7 +23,7 @@ module Hbc
|
||||
env: { "PATH" => PATH.new(Formula["gnupg"].opt_bin, ENV["PATH"]) })
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
import_key
|
||||
|
||||
Dir.mktmpdir do |tmp_unpack_dir|
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\A\037\213/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
Dir.mktmpdir do |tmp_unpack_dir|
|
||||
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\A\]\000\000\200\000/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir])
|
||||
@command.run!("unlzma",
|
||||
args: ["-q", "--", Pathname(unpack_dir).join(basename)],
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
false
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir/basename])
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\ARar!/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("unrar",
|
||||
args: ["x", "-inul", path, unpack_dir],
|
||||
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) })
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("7zr",
|
||||
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
|
||||
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) })
|
||||
|
||||
@ -5,7 +5,7 @@ module Hbc
|
||||
(path/".svn").directory?
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("svn", args: ["export", "--force", path, unpack_dir])
|
||||
end
|
||||
end
|
||||
|
||||
@ -12,7 +12,7 @@ module Hbc
|
||||
end
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("tar", args: ["xf", path, "-C", unpack_dir])
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\Axar!/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("xar", args: ["-x", "-f", @path, "-C", unpack_dir])
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\A\xFD7zXZ\x00/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir])
|
||||
@command.run!("unxz",
|
||||
args: ["-q", "--", unpack_dir/basename],
|
||||
|
||||
@ -7,7 +7,7 @@ module Hbc
|
||||
magic_number.match?(/\APK(\003\004|\005\006)/n)
|
||||
end
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
Dir.mktmpdir do |tmp_unpack_dir|
|
||||
@command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", path, tmp_unpack_dir])
|
||||
|
||||
|
||||
@ -158,7 +158,7 @@ module Hbc
|
||||
raise CaskError, "Uh oh, could not figure out how to unpack '#{@downloaded_path}'."
|
||||
end
|
||||
|
||||
container.new(@cask, @downloaded_path, @command, verbose: verbose?)
|
||||
container.new(@cask, @downloaded_path, @command)
|
||||
end
|
||||
end
|
||||
|
||||
@ -168,7 +168,7 @@ module Hbc
|
||||
odebug "Using container class #{primary_container.class} for #{@downloaded_path}"
|
||||
|
||||
basename = CGI.unescape(File.basename(@cask.url.path))
|
||||
primary_container.extract(to: @cask.staged_path, basename: basename)
|
||||
primary_container.extract(to: @cask.staged_path, basename: basename, verbose: verbose?)
|
||||
end
|
||||
|
||||
def install_artifacts
|
||||
|
||||
@ -48,7 +48,8 @@ class AbstractDownloadStrategy
|
||||
# Unlike {Resource#stage}, this does not take a block.
|
||||
def stage
|
||||
UnpackStrategy.detect(cached_location, ref_type: @ref_type, ref: @ref)
|
||||
.extract_nestedly(basename: basename_without_params)
|
||||
.extract_nestedly(basename: basename_without_params,
|
||||
verbose: ARGV.verbose? && !shutup)
|
||||
end
|
||||
|
||||
# @!attribute [r] cached_location
|
||||
@ -68,7 +69,7 @@ class AbstractDownloadStrategy
|
||||
end
|
||||
|
||||
def safe_system(*args)
|
||||
if @shutup
|
||||
if shutup
|
||||
return if quiet_system(*args)
|
||||
raise(ErrorDuringExecution.new(args, status: $CHILD_STATUS))
|
||||
else
|
||||
|
||||
@ -61,29 +61,29 @@ class UnpackStrategy
|
||||
@ref = ref
|
||||
end
|
||||
|
||||
def extract(to: nil, basename: nil)
|
||||
def extract(to: nil, basename: nil, verbose: false)
|
||||
basename ||= path.basename
|
||||
unpack_dir = Pathname(to || Dir.pwd).expand_path
|
||||
unpack_dir.mkpath
|
||||
extract_to_dir(unpack_dir, basename: basename)
|
||||
extract_to_dir(unpack_dir, basename: basename, verbose: verbose)
|
||||
end
|
||||
|
||||
def extract_nestedly(to: nil, basename: nil)
|
||||
def extract_nestedly(to: nil, basename: nil, verbose: false)
|
||||
Dir.mktmpdir do |tmp_unpack_dir|
|
||||
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||
|
||||
extract(to: tmp_unpack_dir, basename: basename)
|
||||
extract(to: tmp_unpack_dir, basename: basename, verbose: verbose)
|
||||
|
||||
children = tmp_unpack_dir.children
|
||||
|
||||
if children.count == 1 && !children.first.directory?
|
||||
s = self.class.detect(children.first)
|
||||
|
||||
s.extract_nestedly(to: to)
|
||||
s.extract_nestedly(to: to, verbose: verbose)
|
||||
next
|
||||
end
|
||||
|
||||
DirectoryUnpackStrategy.new(tmp_unpack_dir).extract(to: to)
|
||||
DirectoryUnpackStrategy.new(tmp_unpack_dir).extract(to: to, verbose: verbose)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -95,8 +95,8 @@ class DirectoryUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
FileUtils.cp_r File.join(path, "."), unpack_dir, preserve: true
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp_r File.join(path, "."), unpack_dir, preserve: true, verbose: verbose
|
||||
end
|
||||
end
|
||||
|
||||
@ -105,8 +105,8 @@ class UncompressedUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true, verbose: verbose
|
||||
end
|
||||
end
|
||||
|
||||
@ -151,7 +151,7 @@ class P7ZipUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system "7zr", "x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"
|
||||
end
|
||||
end
|
||||
@ -163,8 +163,9 @@ class ZipUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
safe_system "unzip", "-qq", path, "-d", unpack_dir
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
quiet_flags = verbose ? [] : ["-qq"]
|
||||
safe_system "unzip", *quiet_flags, path, "-d", unpack_dir
|
||||
end
|
||||
end
|
||||
|
||||
@ -180,7 +181,7 @@ class TarUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system "tar", "xf", path, "-C", unpack_dir
|
||||
end
|
||||
end
|
||||
@ -198,9 +199,10 @@ class XzUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true
|
||||
safe_system Formula["xz"].opt_bin/"unxz", "-q", "-T0", unpack_dir/basename
|
||||
quiet_flags = verbose ? [] : ["-q"]
|
||||
safe_system Formula["xz"].opt_bin/"unxz", *quiet_flags, "-T0", unpack_dir/basename
|
||||
extract_nested_tar(unpack_dir)
|
||||
end
|
||||
|
||||
@ -224,9 +226,10 @@ class Bzip2UnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true
|
||||
safe_system "bunzip2", "-q", unpack_dir/basename
|
||||
quiet_flags = verbose ? [] : ["-q"]
|
||||
safe_system "bunzip2", *quiet_flags, unpack_dir/basename
|
||||
end
|
||||
end
|
||||
|
||||
@ -237,9 +240,10 @@ class GzipUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true
|
||||
safe_system "gunzip", "-q", "-N", unpack_dir/basename
|
||||
quiet_flags = verbose ? [] : ["-q"]
|
||||
safe_system "gunzip", *quiet_flags, "-N", unpack_dir/basename
|
||||
end
|
||||
end
|
||||
|
||||
@ -250,9 +254,10 @@ class LzipUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
FileUtils.cp path, unpack_dir/basename, preserve: true
|
||||
safe_system Formula["lzip"].opt_bin/"lzip", "-d", "-q", unpack_dir/basename
|
||||
quiet_flags = verbose ? [] : ["-q"]
|
||||
safe_system Formula["lzip"].opt_bin/"lzip", "-d", *quiet_flags, unpack_dir/basename
|
||||
end
|
||||
end
|
||||
|
||||
@ -263,7 +268,7 @@ class XarUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system "xar", "-x", "-f", path, "-C", unpack_dir
|
||||
end
|
||||
end
|
||||
@ -275,7 +280,7 @@ class RarUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system Formula["unrar"].opt_bin/"unrar", "x", "-inul", path, unpack_dir
|
||||
end
|
||||
end
|
||||
@ -287,7 +292,7 @@ class LhaUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system Formula["lha"].opt_bin/"lha", "xq2w=#{unpack_dir}", path
|
||||
end
|
||||
end
|
||||
@ -305,7 +310,7 @@ class SubversionUnpackStrategy < DirectoryUnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
safe_system "svn", "export", "--force", path, unpack_dir
|
||||
end
|
||||
end
|
||||
@ -323,7 +328,7 @@ class MercurialUnpackStrategy < DirectoryUnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
with_env "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) do
|
||||
safe_system "hg", "--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir
|
||||
end
|
||||
@ -341,7 +346,7 @@ class FossilUnpackStrategy < UnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
args = if @ref_type && @ref
|
||||
[@ref]
|
||||
else
|
||||
@ -361,7 +366,7 @@ class BazaarUnpackStrategy < DirectoryUnpackStrategy
|
||||
|
||||
private
|
||||
|
||||
def extract_to_dir(unpack_dir, basename:)
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
super
|
||||
|
||||
# The export command doesn't work on checkouts (see https://bugs.launchpad.net/bzr/+bug/897511).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user