Skip to content

Commit

Permalink
Fix archive extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmartian committed Jan 24, 2024
1 parent c8e9ad8 commit 577b265
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Binary file not shown.
12 changes: 6 additions & 6 deletions spec/octocatalog-diff/tests/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'logger'
require 'rspec'
require 'rspec/retry'
require 'rubygems/package'
require 'tempfile'
require 'tmpdir'

Expand Down Expand Up @@ -210,23 +211,22 @@ def self.test_command(command)
# Check out fixture repo. The repository is a tarball; this extracts it to a temporary directory and returns
# the path where it was checked out. If the checkout fails, returns nil. Note: Be sure to include code in the
# caller to clean up the temporary directory upon exit.
# @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tar)
# @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tgz)
# @return [String] Path to checkout
def self.extract_fixture_repo(repo)
# If tar isn't here, don't do this
has_tar = test_command('tar --version')
return nil unless has_tar.nil?

# Make sure tarball is there
repo_tarball = fixture_path("git-repos/#{repo}.tar")
repo_tarball = fixture_path("git-repos/#{repo}.tgz")
raise Errno::ENOENT, "Repo tarball for #{repo} not found in #{repo_tarball}" unless File.file?(repo_tarball)

# Extract to temporary directory
extract_dir = Dir.mktmpdir
cmd = "tar -xf #{Shellwords.escape(repo_tarball)}"
extract_result, extract_code = Open3.capture2e(cmd, chdir: extract_dir)
return extract_dir if extract_code.exitstatus.zero?
raise "Failed to extract #{repo_tarball}: #{extract_result} (#{extract_code.exitstatus})"
io = File.open(repo_tarball, 'rb')
Gem::Package.new("").extract_tar_gz(io, extract_dir)
return extract_dir
end

# Clean up a temporary directory. This does nothing if the directory doesn't exist, or if it's nil.
Expand Down

0 comments on commit 577b265

Please sign in to comment.