|
2 | 2 | require 'logger'
|
3 | 3 | require 'rspec'
|
4 | 4 | require 'rspec/retry'
|
| 5 | +require 'rubygems/package' |
5 | 6 | require 'tempfile'
|
6 | 7 | require 'tmpdir'
|
7 | 8 |
|
@@ -210,23 +211,22 @@ def self.test_command(command)
|
210 | 211 | # Check out fixture repo. The repository is a tarball; this extracts it to a temporary directory and returns
|
211 | 212 | # the path where it was checked out. If the checkout fails, returns nil. Note: Be sure to include code in the
|
212 | 213 | # caller to clean up the temporary directory upon exit.
|
213 |
| - # @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tar) |
| 214 | + # @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tgz) |
214 | 215 | # @return [String] Path to checkout
|
215 | 216 | def self.extract_fixture_repo(repo)
|
216 | 217 | # If tar isn't here, don't do this
|
217 | 218 | has_tar = test_command('tar --version')
|
218 | 219 | return nil unless has_tar.nil?
|
219 | 220 |
|
220 | 221 | # Make sure tarball is there
|
221 |
| - repo_tarball = fixture_path("git-repos/#{repo}.tar") |
| 222 | + repo_tarball = fixture_path("git-repos/#{repo}.tgz") |
222 | 223 | raise Errno::ENOENT, "Repo tarball for #{repo} not found in #{repo_tarball}" unless File.file?(repo_tarball)
|
223 | 224 |
|
224 | 225 | # Extract to temporary directory
|
225 | 226 | extract_dir = Dir.mktmpdir
|
226 |
| - cmd = "tar -xf #{Shellwords.escape(repo_tarball)}" |
227 |
| - extract_result, extract_code = Open3.capture2e(cmd, chdir: extract_dir) |
228 |
| - return extract_dir if extract_code.exitstatus.zero? |
229 |
| - raise "Failed to extract #{repo_tarball}: #{extract_result} (#{extract_code.exitstatus})" |
| 227 | + io = File.open(repo_tarball, 'rb') |
| 228 | + Gem::Package.new("").extract_tar_gz(io, extract_dir) |
| 229 | + return extract_dir |
230 | 230 | end
|
231 | 231 |
|
232 | 232 | # Clean up a temporary directory. This does nothing if the directory doesn't exist, or if it's nil.
|
|
0 commit comments