Auto-detect nested containers. (#23322)

This commit is contained in:
Markus Reiter 2016-08-02 12:50:24 +02:00
parent 899610b05f
commit 439154cbaf
4 changed files with 47 additions and 5 deletions

View File

@ -4,4 +4,15 @@ class Hbc::Container::Base
@path = path
@command = command
end
def extract_nested(source)
container = Hbc::Container.for_path(source, @command)
return false unless container
ohai "Extracting nested container #{source.basename}"
container.new(@cask, source, @command).extract
true
end
end

View File

@ -8,8 +8,15 @@ class Hbc::Container::Bzip2 < Hbc::Container::Base
def extract
Dir.mktmpdir do |unpack_dir|
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
@command.run!("/usr/bin/bunzip2", args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)])
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
@command.run!("/usr/bin/bunzip2", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
src = Pathname.new(unpack_dir).children[0]
unless @cask.artifacts[:nested_container].empty? &&
extract_nested(src)
dest = @cask.staged_path.join(src.relative_path_from(Pathname.new(unpack_dir)))
FileUtils.mv(src, dest, force: true)
end
end
end
end

View File

@ -8,8 +8,15 @@ class Hbc::Container::Gzip < Hbc::Container::Base
def extract
Dir.mktmpdir do |unpack_dir|
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
@command.run!("/usr/bin/gunzip", args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)])
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
@command.run!("/usr/bin/gunzip", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
src = Pathname.new(unpack_dir).children[0]
unless @cask.artifacts[:nested_container].empty? &&
extract_nested(src)
dest = @cask.staged_path.join(src.relative_path_from(Pathname.new(unpack_dir)))
FileUtils.mv(src, dest, force: true)
end
end
end
end

View File

@ -4,6 +4,23 @@ class Hbc::Container::Zip < Hbc::Container::Base
end
def extract
@command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", @path, @cask.staged_path])
Dir.mktmpdir do |unpack_dir|
@command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", @path, unpack_dir])
children = Pathname.new(unpack_dir).children
nested_container = children[0]
unless children.count == 1 &&
!nested_container.directory? &&
@cask.artifacts[:nested_container].empty? &&
extract_nested(nested_container)
children.each do |src|
dest = @cask.staged_path.join(src.relative_path_from(Pathname.new(unpack_dir)))
FileUtils.rm_r(dest) if dest.exist?
FileUtils.mv(src, dest, force: true)
end
end
end
end
end