Merge pull request #4515 from reitermarkus/extract-nestedly-basename

Add test for basename in `#extract_nestedly`.
This commit is contained in:
Markus Reiter 2018-07-19 21:21:39 +02:00 committed by GitHub
commit 97e549300c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -56,6 +56,23 @@ describe UnpackStrategy do
expect(Pathname.glob(unpack_dir/"**/*")).to include unpack_dir/directories
end
end
context "when extracting a nested archive" do
let(:basename) { "file.xyz" }
let(:path) {
(mktmpdir/basename).tap do |path|
mktmpdir do |dir|
FileUtils.touch dir/"file.txt"
system "tar", "-c", "-f", path, "-C", dir, "file.txt"
end
end
}
it "does not pass down the basename of the archive" do
strategy.extract_nestedly(to: unpack_dir, basename: basename)
expect(unpack_dir/"file.txt").to be_a_file
end
end
end
end

View File

@ -197,10 +197,10 @@ class XzUnpackStrategy < UnpackStrategy
def extract_to_dir(unpack_dir, basename:)
super
safe_system Formula["xz"].opt_bin/"unxz", "-q", "-T0", unpack_dir/basename
extract_nested_tar(unpack_dir, basename: basename)
extract_nested_tar(unpack_dir)
end
def extract_nested_tar(unpack_dir, basename:)
def extract_nested_tar(unpack_dir)
return unless DependencyCollector.tar_needs_xz_dependency?
return if (children = unpack_dir.children).count != 1
return if (tar = children.first).extname != ".tar"
@ -208,7 +208,7 @@ class XzUnpackStrategy < UnpackStrategy
Dir.mktmpdir do |tmpdir|
tmpdir = Pathname(tmpdir)
FileUtils.mv tar, tmpdir/tar.basename
TarUnpackStrategy.new(tmpdir/tar.basename).extract(to: unpack_dir, basename: basename)
TarUnpackStrategy.new(tmpdir/tar.basename).extract(to: unpack_dir)
end
end
end