diff options
author | Tim Smith <tsmith@chef.io> | 2022-02-07 17:45:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 17:45:05 -0800 |
commit | 89db30db2aa5988c4562680f3ad6ab7508db391e (patch) | |
tree | 7200b03ab8a88454f294eea72d7a77349b2a1a2a | |
parent | 4ac2cd38df79f3811768365bd1f1794ea1ff78cb (diff) | |
parent | d00b145f7fc4d22bfa75d8e5b8d3c04e7ccdcf4f (diff) | |
download | chef-89db30db2aa5988c4562680f3ad6ab7508db391e.tar.gz |
Merge pull request #12560 from chef/lcg/16-backport-12552
(Backport) Eager load ffi-libarchive to resolve centos-7 failures
-rw-r--r-- | lib/chef/resource/archive_file.rb | 12 | ||||
-rw-r--r-- | spec/unit/resource/archive_file_spec.rb | 14 |
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb index 4d77ee979b..7af4fc7cb4 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 @@ -88,8 +94,6 @@ class Chef action :extract do description "Extract and archive file." - require_libarchive - unless ::File.exist?(new_resource.path) raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue." end @@ -127,10 +131,6 @@ class Chef 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/unit/resource/archive_file_spec.rb b/spec/unit/resource/archive_file_spec.rb index 6effe550db..6017d68b7e 100644 --- a/spec/unit/resource/archive_file_spec.rb +++ b/spec/unit/resource/archive_file_spec.rb @@ -17,7 +17,19 @@ require "spec_helper" -describe Chef::Resource::ArchiveFile do +begin + require "ffi-libarchive" +rescue LoadError + module Archive + class Reader + def close; end + def each_entry; end + def extract(entry, flags = 0, destination: nil); end + end + end +end + +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) } |