summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-06-03 14:12:59 -0700
committerTim Smith <tsmith84@gmail.com>2020-06-03 14:12:59 -0700
commit3a3f44a03a7b108fd9162701555bcfa034b4a180 (patch)
treec18f3f8be34cc46aad3fc92d487d83178b47e5d0
parent2f78efa0f657c67ea1d8ec04b8fcd645f36d7c7e (diff)
downloadchef-3a3f44a03a7b108fd9162701555bcfa034b4a180.tar.gz
archive_file: move ffi-libarchive into a simple helper methodrequire_archive_file
This way it always gets called in the action, but we can still avoid spec failures on systems that don't have ffi-libarchive Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/archive_file.rb25
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(:|)