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-22 23:18:10 -0700
commit855d018aed8900f25746becb61c5c55d90966f72 (patch)
treeaed81e16973c844cbceda18468c4b88a19017190
parente090d448ce1361471d5cdad9c0e3ac5155918a84 (diff)
downloadchef-15_libarchive.tar.gz
archive_file: move ffi-libarchive into a simple helper method15_libarchive
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.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb
index 3cb451b912..b4eed51137 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
@@ -38,6 +39,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,
@@ -71,11 +84,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
@@ -112,6 +125,16 @@ 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.")
+ end
+ end
+
# This can't be a constant since we might not have required 'ffi-libarchive' yet.
def extract_option_map
{
@@ -135,8 +158,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)
@@ -163,8 +184,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(:|)