diff options
-rw-r--r-- | lib/chef/resource/archive_file.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb index 1c761097a6..4d77ee979b 100644 --- a/lib/chef/resource/archive_file.rb +++ b/lib/chef/resource/archive_file.rb @@ -19,6 +19,7 @@ # require_relative "../resource" +require "fileutils" unless defined?(FileUtils) class Chef class Resource @@ -39,6 +40,18 @@ class Chef destination '/srv/files' end ``` + + **Set specific permissions on the extracted files**: + + ```ruby + archive_file 'Precompiled.zip' do + owner 'tsmith' + group 'staff' + mode '700' + path '/tmp/Precompiled.zip' + destination '/srv/files' + end + ``` DOC property :path, String, @@ -72,11 +85,11 @@ class Chef alias_method :extract_options, :options alias_method :extract_to, :destination - require "fileutils" unless defined?(FileUtils) - 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 @@ -114,6 +127,10 @@ 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.") @@ -143,8 +160,6 @@ class Chef # # @return [Boolean] def archive_differs_from_disk?(src, dest) - require "ffi-libarchive" - modified = false Dir.chdir(dest) do archive = Archive::Reader.open_filename(src) @@ -171,8 +186,6 @@ class Chef # # @return [void] def extract(src, dest, options = []) - require "ffi-libarchive" - converge_by("extract #{src} to #{dest}") do flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|) |