From aa1bc01e0360978d76a7615e096f390c1910be6b Mon Sep 17 00:00:00 2001 From: "YAMASHIRO, Jun" Date: Sun, 10 Jul 2016 23:56:52 +0900 Subject: [PATCH 1/3] Add recursive chmod/chown to remote_directory resource. remote_directory resource with mode/owner/group attributes just only work at root directory("path" attribute). This patch add recursively option. And set default(it is good or bad?). Test case --------- remote_directory '/var/www/html/webapps' do owner 'apache' group 'apache' mode 'g+w' source webapps end --- lib/itamae/resource/remote_directory.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/itamae/resource/remote_directory.rb b/lib/itamae/resource/remote_directory.rb index 42032959..68a79628 100644 --- a/lib/itamae/resource/remote_directory.rb +++ b/lib/itamae/resource/remote_directory.rb @@ -9,6 +9,8 @@ class RemoteDirectory < Base define_attribute :mode, type: String define_attribute :owner, type: String define_attribute :group, type: String + define_attribute :recursive_mode, type: [String, Symbol], default: :true + define_attribute :recursive_owner, type: [String, Symbol], default: :true def pre_action directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path)) @@ -56,10 +58,18 @@ def show_differences def action_create(options) if attributes.mode - run_specinfra(:change_file_mode, @temppath, attributes.mode) + if attributes.recursive_mode == :true + run_specinfra(:change_file_mode, @temppath, attributes.mode, :recursive => true) + else + run_specinfra(:change_file_mode, @temppath, attributes.mode) + end end if attributes.owner || attributes.group - run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group) + if attributes.recursive_owner == :true + run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group, :recursive => true) + else + run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group) + end end if run_specinfra(:check_file_is_file, attributes.path) From a66d06947104a152ebf7a4185021a103fba7256d Mon Sep 17 00:00:00 2001 From: "YAMASHIRO, Jun" Date: Mon, 26 Dec 2016 18:49:46 +0900 Subject: [PATCH 2/3] * Change class to Symbol to TrueClass/FalseClass * Change default value: false on default. --- lib/itamae/resource/remote_directory.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/itamae/resource/remote_directory.rb b/lib/itamae/resource/remote_directory.rb index 68a79628..0bbb730f 100644 --- a/lib/itamae/resource/remote_directory.rb +++ b/lib/itamae/resource/remote_directory.rb @@ -9,8 +9,8 @@ class RemoteDirectory < Base define_attribute :mode, type: String define_attribute :owner, type: String define_attribute :group, type: String - define_attribute :recursive_mode, type: [String, Symbol], default: :true - define_attribute :recursive_owner, type: [String, Symbol], default: :true + define_attribute :recursive_mode, type: [TrueClass, FalseClass], default: false + define_attribute :recursive_owner, type: [TrueClass, FalseClass], default: false def pre_action directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path)) @@ -58,18 +58,10 @@ def show_differences def action_create(options) if attributes.mode - if attributes.recursive_mode == :true - run_specinfra(:change_file_mode, @temppath, attributes.mode, :recursive => true) - else - run_specinfra(:change_file_mode, @temppath, attributes.mode) - end + run_specinfra(:change_file_mode, @temppath, attributes.mode, recursive: attributes.recursive_mode) end if attributes.owner || attributes.group - if attributes.recursive_owner == :true - run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group, :recursive => true) - else - run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group) - end + run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group, recursive: attributes.recursive_owner) end if run_specinfra(:check_file_is_file, attributes.path) From 0f2fb315b30cd4a5311f23566f59b477412511ac Mon Sep 17 00:00:00 2001 From: "YAMASHIRO, Jun" Date: Thu, 29 Dec 2016 19:23:07 +0900 Subject: [PATCH 3/3] Too much long name. But clearly name about target. --- lib/itamae/resource/remote_directory.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/itamae/resource/remote_directory.rb b/lib/itamae/resource/remote_directory.rb index 0bbb730f..d4c0f29d 100644 --- a/lib/itamae/resource/remote_directory.rb +++ b/lib/itamae/resource/remote_directory.rb @@ -10,7 +10,7 @@ class RemoteDirectory < Base define_attribute :owner, type: String define_attribute :group, type: String define_attribute :recursive_mode, type: [TrueClass, FalseClass], default: false - define_attribute :recursive_owner, type: [TrueClass, FalseClass], default: false + define_attribute :recursive_owner_and_group, type: [TrueClass, FalseClass], default: false def pre_action directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path)) @@ -61,7 +61,7 @@ def action_create(options) run_specinfra(:change_file_mode, @temppath, attributes.mode, recursive: attributes.recursive_mode) end if attributes.owner || attributes.group - run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group, recursive: attributes.recursive_owner) + run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group, recursive: attributes.recursive_owner_and_group) end if run_specinfra(:check_file_is_file, attributes.path)