Auto-detect nested containers. (#23322)
This commit is contained in:
parent
899610b05f
commit
439154cbaf
|
@ -4,4 +4,15 @@ class Hbc::Container::Base
|
||||||
@path = path
|
@path = path
|
||||||
@command = command
|
@command = command
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -8,8 +8,15 @@ class Hbc::Container::Bzip2 < Hbc::Container::Base
|
||||||
def extract
|
def extract
|
||||||
Dir.mktmpdir do |unpack_dir|
|
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!("/usr/bin/bunzip2", args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)])
|
@command.run!("/usr/bin/bunzip2", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,8 +8,15 @@ class Hbc::Container::Gzip < Hbc::Container::Base
|
||||||
def extract
|
def extract
|
||||||
Dir.mktmpdir do |unpack_dir|
|
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!("/usr/bin/gunzip", args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)])
|
@command.run!("/usr/bin/gunzip", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
|
||||||
@command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,23 @@ class Hbc::Container::Zip < Hbc::Container::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue