Skip to content

Commit

Permalink
Merge pull request #143 from eagletmt/set-mode-and-owner-at-edit
Browse files Browse the repository at this point in the history
Edit action of file resource should set owner and mode if specified
  • Loading branch information
ryotarai committed Jul 10, 2015
2 parents 88943ea + 58f0c91 commit 1b9aa72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/itamae/resource/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/integration/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b9aa72

Please sign in to comment.