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