Skip to content

Commit

Permalink
Set mode and owner correctly when file not changed
Browse files Browse the repository at this point in the history
Previously always mode and owner had set to temppath even if file content is
not changed.

P.S. we need well-covered tests!
  • Loading branch information
sorah committed Mar 14, 2016
1 parent e5c3341 commit 438d79e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/itamae/resource/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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

Expand Down

1 comment on commit 438d79e

@ryotarai
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Please sign in to comment.