summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) }