From 4cff1e785b66c39a1fecc660ce3832685517a89c Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 7 Feb 2022 17:20:28 -0800 Subject: [PATCH] (Backport) Eager load ffi-libarchive to resolve centos-7 failures backport of #12552 Signed-off-by: Lamont Granquist --- lib/chef/resource/archive_file.rb | 12 ++++++------ spec/functional/resource/archive_file_spec.rb | 5 +++-- spec/spec_helper.rb | 2 -- spec/unit/resource/archive_file_spec.rb | 3 +-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb index 9acec4213cf..1a27786336c 100644 --- a/lib/chef/resource/archive_file.rb +++ b/lib/chef/resource/archive_file.rb @@ -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 @@ -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 @@ -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.") diff --git a/spec/functional/resource/archive_file_spec.rb b/spec/functional/resource/archive_file_spec.rb index 27815cb3194..94da76c4f2f 100644 --- a/spec/functional/resource/archive_file_spec.rb +++ b/spec/functional/resource/archive_file_spec.rb @@ -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 } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5cd04437be2..2aa3b2a1cd1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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) diff --git a/spec/unit/resource/archive_file_spec.rb b/spec/unit/resource/archive_file_spec.rb index 88cbe946291..7818a31516c 100644 --- a/spec/unit/resource/archive_file_spec.rb +++ b/spec/unit/resource/archive_file_spec.rb @@ -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) }