From 58f0c91f708aa2252c8dc2145f9f53aeb5207756 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Fri, 10 Jul 2015 17:35:19 +0900 Subject: [PATCH] Edit action of file resource should set owner and mode if specified --- lib/itamae/resource/file.rb | 14 ++++++++++++-- spec/integration/default_spec.rb | 6 +++--- spec/integration/recipes/default.rb | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/itamae/resource/file.rb b/lib/itamae/resource/file.rb index d5f78fba..3d69f121 100644 --- a/lib/itamae/resource/file.rb +++ b/lib/itamae/resource/file.rb @@ -81,8 +81,18 @@ def action_delete(options) end def action_edit(options) - run_command(['chmod', '--reference', attributes.path, @temppath]) - run_command(['chown', '--reference', attributes.path, @temppath]) + if attributes.mode + run_specinfra(:change_file_mode, @temppath, attributes.mode) + else + run_command(['chmod', '--reference', attributes.path, @temppath]) + end + + if attributes.owner || attributes.group + run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group) + else + run_command(['chown', '--reference', attributes.path, @temppath]) + end + run_specinfra(:move_file, @temppath, attributes.path) end diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index ffd12a58..ec3a1636 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -163,9 +163,9 @@ describe file('/tmp/file_edit_sample') do it { should be_file } its(:content) { should eq("Hello, Itamae") } - it { should be_mode 444 } - it { should be_owned_by "itamae" } - it { should be_grouped_into "itamae" } + it { should be_mode 400 } + it { should be_owned_by "itamae2" } + it { should be_grouped_into "itamae2" } end describe file('/home/itamae2') do diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 71002048..5155cb32 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -318,6 +318,9 @@ file '/tmp/file_edit_sample' do action :edit + owner 'itamae2' + group 'itamae2' + mode '400' block do |content| content.gsub!('world', 'Itamae') end