Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for basename in #extract_nestedly. #4515

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Library/Homebrew/test/unpack_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@
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

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ def self.can_extract?(path:, magic_number:)
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"

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
Expand Down