Assimilate Containers with UnpackStrategy.
This commit is contained in:
parent
c47d51519e
commit
e5865e7e7f
@ -28,7 +28,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
ohai "Extracting nested container #{path.relative_path_from(cask.staged_path)}"
|
ohai "Extracting nested container #{path.relative_path_from(cask.staged_path)}"
|
||||||
container.new(cask, path, command, verbose: verbose).extract
|
container.new(cask, path, command, verbose: verbose).extract(to: cask.staged_path)
|
||||||
FileUtils.remove_entry_secure(path)
|
FileUtils.remove_entry_secure(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,9 +7,7 @@ module Hbc
|
|||||||
path.extname == ".air"
|
path.extname == ".air"
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!(
|
@command.run!(
|
||||||
"/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer",
|
"/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer",
|
||||||
args: ["-silent", "-location", unpack_dir, path],
|
args: ["-silent", "-location", unpack_dir, path],
|
||||||
|
|||||||
@ -1,21 +1,27 @@
|
|||||||
module Hbc
|
module Hbc
|
||||||
class Container
|
class Container
|
||||||
class Base
|
class Base
|
||||||
|
extend Predicable
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
|
||||||
|
attr_predicate :verbose?
|
||||||
|
|
||||||
def initialize(cask, path, command, nested: false, verbose: false)
|
def initialize(cask, path, command, nested: false, verbose: false)
|
||||||
@cask = cask
|
@cask = cask
|
||||||
@path = path
|
@path = path
|
||||||
@command = command
|
@command = command
|
||||||
@nested = nested
|
|
||||||
@verbose = verbose
|
@verbose = verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
def verbose?
|
def extract(to: nil, basename: nil)
|
||||||
@verbose
|
basename ||= path.basename
|
||||||
|
unpack_dir = Pathname(to || Dir.pwd).expand_path
|
||||||
|
unpack_dir.mkpath
|
||||||
|
extract_to_dir(unpack_dir, basename: basename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_nested_inside(dir)
|
def extract_nested_inside(dir, to:)
|
||||||
children = Pathname.new(dir).children
|
children = Pathname.new(dir).children
|
||||||
|
|
||||||
nested_container = children[0]
|
nested_container = children[0]
|
||||||
@ -23,7 +29,7 @@ module Hbc
|
|||||||
unless children.count == 1 &&
|
unless children.count == 1 &&
|
||||||
!nested_container.directory? &&
|
!nested_container.directory? &&
|
||||||
@cask.artifacts.none? { |a| a.is_a?(Artifact::NestedContainer) } &&
|
@cask.artifacts.none? { |a| a.is_a?(Artifact::NestedContainer) } &&
|
||||||
extract_nested_container(nested_container)
|
extract_nested_container(nested_container, to: to)
|
||||||
|
|
||||||
children.each do |src|
|
children.each do |src|
|
||||||
dest = @cask.staged_path.join(src.basename)
|
dest = @cask.staged_path.join(src.basename)
|
||||||
@ -33,13 +39,13 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_nested_container(source)
|
def extract_nested_container(source, to:)
|
||||||
container = Container.for_path(source)
|
container = Container.for_path(source)
|
||||||
|
|
||||||
return false unless container
|
return false unless container
|
||||||
|
|
||||||
ohai "Extracting nested container #{source.basename}"
|
ohai "Extracting nested container #{source.basename}"
|
||||||
container.new(@cask, source, @command, nested: true, verbose: verbose?).extract
|
container.new(@cask, source, @command, verbose: verbose?).extract(to: to)
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,12 +7,14 @@ module Hbc
|
|||||||
magic_number.match?(/\ABZh/n)
|
magic_number.match?(/\ABZh/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
Dir.mktmpdir do |unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
|
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||||
@command.run!("bunzip2", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
|
|
||||||
|
|
||||||
extract_nested_inside(unpack_dir)
|
FileUtils.cp path, tmp_unpack_dir/basename, preserve: true
|
||||||
|
@command.run!("bunzip2", args: ["--quiet", "--", tmp_unpack_dir/basename])
|
||||||
|
|
||||||
|
extract_nested_inside(tmp_unpack_dir, to: unpack_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,13 +7,10 @@ module Hbc
|
|||||||
magic_number.match?(/\A(MSCF|MZ)/n)
|
magic_number.match?(/\A(MSCF|MZ)/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
Dir.mktmpdir do |unpack_dir|
|
|
||||||
@command.run!("cabextract",
|
@command.run!("cabextract",
|
||||||
args: ["-d", unpack_dir, "--", @path],
|
args: ["-d", unpack_dir, "--", path],
|
||||||
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) })
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependencies
|
def dependencies
|
||||||
|
|||||||
@ -14,11 +14,13 @@ module Hbc
|
|||||||
!imageinfo.empty?
|
!imageinfo.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
mount do |mounts|
|
mount do |mounts|
|
||||||
begin
|
begin
|
||||||
raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad disk image?" if mounts.empty?
|
raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad disk image?" if mounts.empty?
|
||||||
mounts.each(&method(:extract_mount))
|
mounts.each do |mount|
|
||||||
|
extract_mount(mount, to: unpack_dir)
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
mounts.each(&method(:eject))
|
mounts.each(&method(:eject))
|
||||||
end
|
end
|
||||||
@ -84,7 +86,7 @@ module Hbc
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def extract_mount(mount)
|
def extract_mount(mount, to:)
|
||||||
Tempfile.open(["", ".bom"]) do |bomfile|
|
Tempfile.open(["", ".bom"]) do |bomfile|
|
||||||
bomfile.close
|
bomfile.close
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ module Hbc
|
|||||||
filelist.close
|
filelist.close
|
||||||
|
|
||||||
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
|
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
|
||||||
@command.run!("/usr/bin/ditto", args: ["--bom", bomfile.path, "--", mount, @cask.staged_path])
|
@command.run!("/usr/bin/ditto", args: ["--bom", bomfile.path, "--", mount, to])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,9 +7,7 @@ module Hbc
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!("unar",
|
@command.run!("unar",
|
||||||
args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", path],
|
args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", path],
|
||||||
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) })
|
||||||
|
|||||||
@ -23,15 +23,15 @@ module Hbc
|
|||||||
env: { "PATH" => PATH.new(Formula["gnupg"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["gnupg"].opt_bin, ENV["PATH"]) })
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
import_key
|
import_key
|
||||||
|
|
||||||
Dir.mktmpdir do |unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
@command.run!("gpg",
|
@command.run!("gpg",
|
||||||
args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(@path.basename(".gpg")), "--decrypt", @path],
|
args: ["--batch", "--yes", "--output", Pathname(tmp_unpack_dir).join(basename.basename(".gpg")), "--decrypt", path],
|
||||||
env: { "PATH" => PATH.new(Formula["gnupg"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["gnupg"].opt_bin, ENV["PATH"]) })
|
||||||
|
|
||||||
extract_nested_inside(unpack_dir)
|
extract_nested_inside(tmp_unpack_dir, to: unpack_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,14 @@ module Hbc
|
|||||||
magic_number.match?(/\A\037\213/n)
|
magic_number.match?(/\A\037\213/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
Dir.mktmpdir do |unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
|
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||||
@command.run!("gunzip", args: ["--quiet", "--name", "--", Pathname.new(unpack_dir).join(@path.basename)])
|
|
||||||
|
|
||||||
extract_nested_inside(unpack_dir)
|
FileUtils.cp path, tmp_unpack_dir/basename, preserve: true
|
||||||
|
@command.run!("gunzip", args: ["--quiet", "--name", "--", tmp_unpack_dir/basename])
|
||||||
|
|
||||||
|
extract_nested_inside(tmp_unpack_dir, to: unpack_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,14 +7,11 @@ module Hbc
|
|||||||
magic_number.match?(/\A\]\000\000\200\000/n)
|
magic_number.match?(/\A\]\000\000\200\000/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
Dir.mktmpdir do |unpack_dir|
|
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir])
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
|
|
||||||
@command.run!("unlzma",
|
@command.run!("unlzma",
|
||||||
args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)],
|
args: ["-q", "--", Pathname(unpack_dir).join(basename)],
|
||||||
env: { "PATH" => PATH.new(Formula["unlzma"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["unlzma"].opt_bin, ENV["PATH"]) })
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependencies
|
def dependencies
|
||||||
|
|||||||
@ -7,13 +7,8 @@ module Hbc
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", @path, @cask.staged_path.join(target_file)])
|
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir/basename])
|
||||||
end
|
|
||||||
|
|
||||||
def target_file
|
|
||||||
return @path.basename if @nested
|
|
||||||
CGI.unescape(File.basename(@cask.url.path))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,10 +7,10 @@ module Hbc
|
|||||||
magic_number.match?(/\ARar!/n)
|
magic_number.match?(/\ARar!/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
path = @path
|
@command.run!("unrar",
|
||||||
unpack_dir = @cask.staged_path
|
args: ["x", "-inul", path, unpack_dir],
|
||||||
@command.run!(Formula["unrar"].opt_bin/"unrar", args: ["x", "-inul", path, unpack_dir])
|
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) })
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependencies
|
def dependencies
|
||||||
|
|||||||
@ -7,9 +7,7 @@ module Hbc
|
|||||||
magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n)
|
magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!("7zr",
|
@command.run!("7zr",
|
||||||
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
|
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
|
||||||
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) })
|
||||||
|
|||||||
@ -5,10 +5,7 @@ module Hbc
|
|||||||
(path/".svn").directory?
|
(path/".svn").directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
path = @path
|
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!("svn", args: ["export", "--force", path, unpack_dir])
|
@command.run!("svn", args: ["export", "--force", path, unpack_dir])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,9 +12,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!("tar", args: ["xf", path, "-C", unpack_dir])
|
@command.run!("tar", args: ["xf", path, "-C", unpack_dir])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,9 +7,7 @@ module Hbc
|
|||||||
magic_number.match?(/\Axar!/n)
|
magic_number.match?(/\Axar!/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
|
|
||||||
@command.run!("xar", args: ["-x", "-f", @path, "-C", unpack_dir])
|
@command.run!("xar", args: ["-x", "-f", @path, "-C", unpack_dir])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,12 +7,9 @@ module Hbc
|
|||||||
magic_number.match?(/\A\xFD7zXZ\x00/n)
|
magic_number.match?(/\A\xFD7zXZ\x00/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
unpack_dir = @cask.staged_path
|
|
||||||
basename = path.basename
|
|
||||||
|
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir])
|
@command.run!("/usr/bin/ditto", args: ["--", path, unpack_dir])
|
||||||
@command.run!("xz",
|
@command.run!("unxz",
|
||||||
args: ["-q", "--", unpack_dir/basename],
|
args: ["-q", "--", unpack_dir/basename],
|
||||||
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) })
|
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) })
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,11 +7,11 @@ module Hbc
|
|||||||
magic_number.match?(/\APK(\003\004|\005\006)/n)
|
magic_number.match?(/\APK(\003\004|\005\006)/n)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
def extract_to_dir(unpack_dir, basename:)
|
||||||
Dir.mktmpdir do |unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
@command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", @path, unpack_dir])
|
@command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", path, tmp_unpack_dir])
|
||||||
|
|
||||||
extract_nested_inside(unpack_dir)
|
extract_nested_inside(tmp_unpack_dir, to: unpack_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,6 +6,8 @@ require "hbc/cask_dependencies"
|
|||||||
require "hbc/staged"
|
require "hbc/staged"
|
||||||
require "hbc/verify"
|
require "hbc/verify"
|
||||||
|
|
||||||
|
require "cgi"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
class Installer
|
class Installer
|
||||||
extend Predicable
|
extend Predicable
|
||||||
@ -164,8 +166,9 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
odebug "Using container class #{primary_container.class} for #{@downloaded_path}"
|
odebug "Using container class #{primary_container.class} for #{@downloaded_path}"
|
||||||
FileUtils.mkdir_p @cask.staged_path
|
|
||||||
primary_container.extract
|
basename = CGI.unescape(File.basename(@cask.url.path))
|
||||||
|
primary_container.extract(to: @cask.staged_path, basename: basename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_artifacts
|
def install_artifacts
|
||||||
|
|||||||
@ -5,7 +5,7 @@ describe Hbc::Container::Naked, :cask do
|
|||||||
version "1.2"
|
version "1.2"
|
||||||
end
|
end
|
||||||
|
|
||||||
path = "/tmp/downloads/kevin-spacey-1.2.pkg"
|
path = Pathname("/tmp/downloads/kevin-spacey.pkg")
|
||||||
expected_destination = cask.staged_path.join("kevin spacey.pkg")
|
expected_destination = cask.staged_path.join("kevin spacey.pkg")
|
||||||
|
|
||||||
container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand)
|
container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand)
|
||||||
@ -15,7 +15,7 @@ describe Hbc::Container::Naked, :cask do
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
container.extract
|
container.extract(to: cask.staged_path, basename: "kevin spacey.pkg")
|
||||||
}.not_to raise_error
|
}.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -46,7 +46,7 @@ describe Hbc::Installer, :cask do
|
|||||||
Hbc::Installer.new(asset).install
|
Hbc::Installer.new(asset).install
|
||||||
|
|
||||||
expect(Hbc::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory
|
expect(Hbc::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory
|
||||||
expect(Hbc::Config.global.appdir.join("container-bzip2--#{asset.version}")).to be_a_file
|
expect(Hbc::Config.global.appdir.join("container")).to be_a_file
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works with pure gzip-based Casks" do
|
it "works with pure gzip-based Casks" do
|
||||||
|
|||||||
@ -5,5 +5,5 @@ cask 'container-bzip2' do
|
|||||||
url "file://#{TEST_FIXTURE_DIR}/cask/container.bz2"
|
url "file://#{TEST_FIXTURE_DIR}/cask/container.bz2"
|
||||||
homepage 'https://example.com/container-bzip2'
|
homepage 'https://example.com/container-bzip2'
|
||||||
|
|
||||||
app 'container-bzip2--1.2.3'
|
app 'container'
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user