From 438d79e4ef714f637f8f1cb50b01293e5232340a Mon Sep 17 00:00:00 2001 From: "sorah (Shota Fukumori)" Date: Tue, 15 Mar 2016 02:13:08 +0900 Subject: [PATCH] Set mode and owner correctly when file not changed Previously always mode and owner had set to temppath even if file content is not changed. P.S. we need well-covered tests! --- lib/itamae/resource/file.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/itamae/resource/file.rb b/lib/itamae/resource/file.rb index eab7fab1..f56ed3ff 100644 --- a/lib/itamae/resource/file.rb +++ b/lib/itamae/resource/file.rb @@ -60,15 +60,6 @@ def action_create(options) run_command(["touch", attributes.path]) end - change_target = @temppath || attributes.path - - if attributes.mode - run_specinfra(:change_file_mode, change_target, attributes.mode) - end - if attributes.owner || attributes.group - run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group) - end - if @temppath if run_specinfra(:check_file_is_file, attributes.path) unless check_command(["diff", "-q", @temppath, attributes.path]) @@ -79,10 +70,20 @@ def action_create(options) # new file updated! end + end - if updated? - run_specinfra(:move_file, @temppath, attributes.path) - end + change_target = @temppath && updated? ? @temppath : attributes.path + + if attributes.mode + run_specinfra(:change_file_mode, change_target, attributes.mode) + end + + if attributes.owner || attributes.group + run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group) + end + + if @temppath && updated? + run_specinfra(:move_file, @temppath, attributes.path) end end