summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2022-02-07 17:20:28 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2022-02-07 17:32:51 -0800
commitd00b145f7fc4d22bfa75d8e5b8d3c04e7ccdcf4f (patch)
tree7200b03ab8a88454f294eea72d7a77349b2a1a2a
parent4ac2cd38df79f3811768365bd1f1794ea1ff78cb (diff)
downloadchef-d00b145f7fc4d22bfa75d8e5b8d3c04e7ccdcf4f.tar.gz
(Backport) Eager load ffi-libarchive to resolve centos-7 failures
backport of #12552 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/resource/archive_file.rb12
-rw-r--r--spec/unit/resource/archive_file_spec.rb14
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) }