summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-06-03 11:29:13 -0700
committerTim Smith <tsmith84@gmail.com>2020-06-03 11:29:13 -0700
commit0b6c70361f360cc701cb8d1e9d0f09c683d0fec2 (patch)
tree6ed4354bbb1cfce42d0bd68707dc82d0e6660c4d /lib
parentcb57400ec0048a162909875b769b7366cdd30204 (diff)
downloadchef-0b6c70361f360cc701cb8d1e9d0f09c683d0fec2.tar.gz
archive_file: better handle mode property and deprecate Integer valuesfix_file_mode
FileUtils.mkdir_p expects the mode to be in octal form. We accept Integers, but Ruby doesn't have a way to tell if what the user passed was octal or not. The safest thing to do here is to only accept mode as a String and then convert it to octal form with .to_i(8). This adds a new deprecation and correctly sets the file mode value as octal. Right now this feature works like this: String mode: applies wrong permission Base 10 mode: applies wrong permissions Octal mode: Works New behavior: String mode: Works Base 10 mode: Works but throws a deprecation warning Octal mode: applies the wrong permissions and throws a deprecation warning Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/deprecated.rb4
-rw-r--r--lib/chef/resource/archive_file.rb11
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb
index 9ac08f43ee..d67cee8153 100644
--- a/lib/chef/deprecated.rb
+++ b/lib/chef/deprecated.rb
@@ -237,6 +237,10 @@ class Chef
target 29
end
+ class ArchiveFileIntegerFileMode < Base
+ target 30
+ end
+
class Generic < Base
def url
"https://docs.chef.io/chef_deprecations_client/"
diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb
index 58e106d9bc..c02d160729 100644
--- a/lib/chef/resource/archive_file.rb
+++ b/lib/chef/resource/archive_file.rb
@@ -53,7 +53,7 @@ class Chef
description: "The group of the extracted files."
property :mode, [String, Integer],
- description: "The mode of the extracted files.",
+ description: "The mode of the extracted files. Integer values are deprecated as octal strings (ex. 0755) would not be interpreted correctly.",
default: "755"
property :destination, String,
@@ -85,7 +85,8 @@ class Chef
Chef::Log.trace("File or directory does not exist at destination path: #{new_resource.destination}")
converge_by("create directory #{new_resource.destination}") do
- FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_i)
+ # @todo when we remove the ability for mode to be an int we can remove the .to_s below
+ FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_s.to_i(8))
end
extract(new_resource.path, new_resource.destination, Array(new_resource.options))
@@ -113,6 +114,12 @@ class Chef
end
action_class do
+ 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
{