-
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
Keep mtime if no change #212
Conversation
Except no change case, because after this commit changes its behavior.
* Same behavior as create action.
Umm... nishidayuya/keep_mtime_if_no_change branch has following commits.
But GitHub.com list commits with sort by Date. |
Wercker pass
|
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 comment
The reason will be displayed to describe this comment to others. Learn more.
How about using gsub like content.gsub!(/\A.+\z/, "Hello, world")
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.
Thanks for your response!
I fixed it using gsub!
as /tmp/file_edit_sample
. (8a1cf21)
…mp/file_edit_sample using gsub!.
memo:
|
It may be due to timezone. The following can fix the problem
|
Thanks! If I set diff --git a/spec/integration/Vagrantfile b/spec/integration/Vagrantfile
index e663a73..587e47c 100644
--- a/spec/integration/Vagrantfile
+++ b/spec/integration/Vagrantfile
@@ -17,6 +17,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
mv /tmp/sources.list /etc/apt/sources.list
apt-get update
fi
+ echo America/New_York > /etc/timezone
+ dpkg-reconfigure --frontend noninteractive tzdata
EOC
end
|
In Vagrantfile, VirtualBox provider section emulates DigitalOcean provider timezone.
Done. And Wercker pass. |
I didn't meant changing timezone. If you pass time to touch command like |
1ebf3cf includes following:
|
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make any change because owner
is got fromrun_specinfra(:get_file_owner_user, attributes.path)
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.
I understand following:
- Case:
attributes.modified
is true.change_target
is@temppath
.- need
:change_file_owner
.
- Case:
attributes.modified
is false.change_target
isattributes.path
.- DON'T need
:change_file_owner
.
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?
(elsif attributes.modified
removes extra run_specinfra
calling)
How about this? change_target = attributes.modified ? @temppath : attributes.path
if attributes.mode || attributes.modified
mode = attributes.mode || run_specinfra(:get_file_mode, attributes.path).stdout.chomp
run_specinfra(:change_file_mode, change_target, mode)
end
if attributes.owner || attributes.group || attributes.modified
owner = attributes.owner || run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
group = attributes.group || run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
run_specinfra(:change_file_owner, change_target, owner, group)
end
if attributes.modified
run_specinfra(:move_file, @temppath, attributes.path)
end |
I like it. Its code looks like I have fixed and Wercker passed. |
Sorry for late reply. I'll merge this |
No problem. Thank you for your merging and nice reviews! |
Before this PR, Itamae always change mtime in file resource edit action.
After this PR, Itamae change mtime only changing file content.
This PR makes edit action mtime behavior as create action.