-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep mtime if no change #212
Changes from 4 commits
31ac5b8
654a533
f59eeff
25c6e74
8a1cf21
4a02e9a
1ebf3cf
2738138
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,23 +84,27 @@ def action_delete(options) | |
end | ||
|
||
def action_edit(options) | ||
change_target = attributes.modified ? @temppath : attributes.path | ||
|
||
if attributes.mode | ||
run_specinfra(:change_file_mode, @temppath, attributes.mode) | ||
run_specinfra(:change_file_mode, change_target, attributes.mode) | ||
else | ||
mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp | ||
run_specinfra(:change_file_mode, @temppath, mode) | ||
run_specinfra(:change_file_mode, change_target, mode) | ||
end | ||
|
||
if attributes.owner || attributes.group | ||
run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group) | ||
run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group) | ||
else | ||
owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp | ||
group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp | ||
run_specinfra(:change_file_owner, @temppath, owner) | ||
run_specinfra(:change_file_group, @temppath, group) | ||
run_specinfra(:change_file_owner, change_target, owner) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't make any change because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand following:
So I must fix to following: diff --git a/lib/itamae/resource/file.rb b/lib/itamae/resource/file.rb
index d938523..1d26af7 100644
--- a/lib/itamae/resource/file.rb
+++ b/lib/itamae/resource/file.rb
@@ -95,11 +95,11 @@ def action_edit(options)
if attributes.owner || attributes.group
run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
- else
+ elsif attributes.modified
owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
- run_specinfra(:change_file_owner, change_target, owner)
- run_specinfra(:change_file_group, change_target, group)
+ run_specinfra(:change_file_owner, @temppath, owner)
+ run_specinfra(:change_file_group, @temppath, group)
end
if attributes.modified Is it OK? ( |
||
run_specinfra(:change_file_group, change_target, group) | ||
end | ||
|
||
run_specinfra(:move_file, @temppath, attributes.path) | ||
if attributes.modified | ||
run_specinfra(:move_file, @temppath, attributes.path) | ||
end | ||
end | ||
|
||
private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,6 +402,28 @@ | |
|
||
### | ||
|
||
execute "touch -d 2016-05-02T01:23:45 /tmp/file_edit_with_content_change_updates_timestamp" | ||
|
||
file "/tmp/file_edit_with_content_change_updates_timestamp" do | ||
action :edit | ||
block do |content| | ||
content[0 .. -1] = "Hello, world" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using gsub like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your response! I fixed it using |
||
end | ||
end | ||
|
||
### | ||
|
||
execute "touch -d 2016-05-02T12:34:56 /tmp/file_edit_without_content_change_keeping_timestamp" | ||
|
||
file "/tmp/file_edit_without_content_change_keeping_timestamp" do | ||
action :edit | ||
block do |content| | ||
# no change | ||
end | ||
end | ||
|
||
### | ||
|
||
file '/tmp/file_without_content_change_updates_mode_and_owner' do | ||
action :create | ||
content 'Hello, world' | ||
|
@@ -420,6 +442,22 @@ | |
|
||
### | ||
|
||
execute "touch -d 2016-05-01T01:23:45 /tmp/file_with_content_change_updates_timestamp" | ||
|
||
file "/tmp/file_with_content_change_updates_timestamp" do | ||
content "Hello, world" | ||
end | ||
|
||
### | ||
|
||
execute "echo 'Hello, world' > /tmp/file_without_content_change_keeping_timestamp ; touch -d 2016-05-01T12:34:56 /tmp/file_without_content_change_keeping_timestamp" | ||
|
||
file "/tmp/file_without_content_change_keeping_timestamp" do | ||
content "Hello, world\n" | ||
end | ||
|
||
### | ||
|
||
unless run_command("echo -n Hello").stdout == "Hello" | ||
raise "run_command in a recipe failed" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has same problem as
:change_file_owner
. I'll fix.