Skip to content

Commit

Permalink
Merge pull request #12559 from chef/lcg/17-backport-12552
Browse files Browse the repository at this point in the history
(Backport) Eager load ffi-libarchive to resolve centos-7 failures
  • Loading branch information
tas50 committed Feb 8, 2022
2 parents df3d3db + 4cff1e7 commit bad5817
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/chef/resource/archive_file.rb
Expand Up @@ -20,6 +20,12 @@

require_relative "../resource"
require "fileutils" unless defined?(FileUtils)
begin
# ffi-libarchive must be eager loaded see: https://github.com/chef/chef/issues/12228
require "ffi-libarchive" unless defined?(Archive::Reader)
rescue LoadError
STDERR.puts "ffi-libarchive could not be loaded, libarchive is probably not installed on system, archive_file will not be available"
end

class Chef
class Resource
Expand Down Expand Up @@ -92,8 +98,6 @@ class ArchiveFile < Chef::Resource

action :extract, description: "Extract and archive file." do

require_libarchive

unless ::File.exist?(new_resource.path)
raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue."
end
Expand Down Expand Up @@ -131,10 +135,6 @@ class ArchiveFile < Chef::Resource
end

action_class do
def require_libarchive
require "ffi-libarchive"
end

def define_resource_requirements
if new_resource.mode.is_a?(Integer)
Chef.deprecated(:archive_file_integer_file_mode, "The mode property should be passed to archive_file resources as a String and not an Integer to ensure the value is properly interpreted.")
Expand Down
5 changes: 3 additions & 2 deletions spec/functional/resource/archive_file_spec.rb
Expand Up @@ -18,8 +18,9 @@
require "spec_helper"
require "tmpdir"

# Exclude this test on platforms where ffi-libarchive loading is broken
describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
# AIX is broken, see https://github.com/chef/omnibus-software/issues/1566
# Windows tests are disbled since we'd need libarchive on windows testers in buildkite for PRs
describe Chef::Resource::ArchiveFile, :not_supported_on_aix, :not_supported_on_windows do
include RecipeDSLHelper

let(:tmp_path) { Dir.mktmpdir }
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -187,8 +187,6 @@ def self.from(system_exit)
config.filter_run_excluding not_rhel7: true if rhel7?
config.filter_run_excluding not_intel_64bit: true if intel_64bit?

config.filter_run_excluding libarchive_loading_broken: true if aix? || amazon_linux? || rhel7?

# these let us use chef: ">= 13" or ruby: "~> 2.0.0" or any other Gem::Dependency-style constraint
config.filter_run_excluding chef: DependencyProc.with(Chef::VERSION)
config.filter_run_excluding ruby: DependencyProc.with(RUBY_VERSION)
Expand Down
3 changes: 1 addition & 2 deletions spec/unit/resource/archive_file_spec.rb
Expand Up @@ -29,8 +29,7 @@ def extract(entry, flags = 0, destination: nil); end
end
end

# Exclude this test on platforms where ffi-libarchive loading is broken
describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
describe Chef::Resource::ArchiveFile, :not_supported_on_aix do
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let(:run_context) { Chef::RunContext.new(node, {}, events) }
Expand Down

0 comments on commit bad5817

Please sign in to comment.