From 31ac5b8076f03f59685c90219f1201da58f87738 Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Fri, 6 May 2016 03:31:28 +0900 Subject: [PATCH 1/8] Remove extra blank line. --- spec/integration/default_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index a5286cff..6f75bd68 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -239,4 +239,3 @@ it { should be_owned_by "itamae2" } it { should be_grouped_into "itamae2" } end - From 654a533fc4a84020c355b81b7c1ca9b7d8a844c4 Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Thu, 5 May 2016 15:37:20 +0900 Subject: [PATCH 2/8] Add spec for mtime in create action --- spec/integration/default_spec.rb | 8 ++++++++ spec/integration/recipes/default.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index 6f75bd68..18b1f1a6 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -239,3 +239,11 @@ it { should be_owned_by "itamae2" } it { should be_grouped_into "itamae2" } end + +describe file('/tmp/file_with_content_change_updates_timestamp') do + its(:mtime) { should be > DateTime.iso8601("2016-05-01T01:23:45Z") } +end + +describe file('/tmp/file_without_content_change_keeping_timestamp') do + its(:mtime) { should eq(DateTime.iso8601("2016-05-01T12:34:56Z")) } +end diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 14323284..b5a21503 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -420,6 +420,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 From f59eeffa3461e9163b86c50f08213b029399332e Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Fri, 6 May 2016 05:05:09 +0900 Subject: [PATCH 3/8] Add spec for mtime in edit action Except no change case, because after this commit changes its behavior. --- spec/integration/default_spec.rb | 4 ++++ spec/integration/recipes/default.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index 18b1f1a6..6a33a60a 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -216,6 +216,10 @@ it { should be_grouped_into "itamae" } end +describe file('/tmp/file_edit_with_content_change_updates_timestamp') do + its(:mtime) { should be > DateTime.iso8601("2016-05-02T01:23:45Z") } +end + describe file('/home/itamae2') do it { should be_directory } it { should be_owned_by "itamae2" } diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index b5a21503..a5cc3c94 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -402,6 +402,17 @@ ### +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" + end +end + +### + file '/tmp/file_without_content_change_updates_mode_and_owner' do action :create content 'Hello, world' From 25c6e74090dd98d5873c805033757c2043902861 Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Wed, 4 May 2016 02:05:56 +0900 Subject: [PATCH 4/8] Keep file mtime if no change. * Same behavior as create action. --- lib/itamae/resource/file.rb | 16 ++++++++++------ spec/integration/default_spec.rb | 4 ++++ spec/integration/recipes/default.rb | 11 +++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/itamae/resource/file.rb b/lib/itamae/resource/file.rb index 5c7b5d42..d9385232 100644 --- a/lib/itamae/resource/file.rb +++ b/lib/itamae/resource/file.rb @@ -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) + 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 diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index 6a33a60a..dc432e5e 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -220,6 +220,10 @@ its(:mtime) { should be > DateTime.iso8601("2016-05-02T01:23:45Z") } end +describe file('/tmp/file_edit_without_content_change_keeping_timestamp') do + its(:mtime) { should eq(DateTime.iso8601("2016-05-02T12:34:56Z")) } +end + describe file('/home/itamae2') do it { should be_directory } it { should be_owned_by "itamae2" } diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index a5cc3c94..001e5906 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -413,6 +413,17 @@ ### +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' From 8a1cf212d74f7adc328c756d7b100c1ef2df927e Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Mon, 9 May 2016 18:15:57 +0900 Subject: [PATCH 5/8] Fix /tmp/file_edit_with_content_change_updates_timestamp recipe as /tmp/file_edit_sample using gsub!. --- spec/integration/recipes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 001e5906..00811d39 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -402,12 +402,12 @@ ### -execute "touch -d 2016-05-02T01:23:45 /tmp/file_edit_with_content_change_updates_timestamp" +execute "f=/tmp/file_edit_with_content_change_updates_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-02T01:23:45 $f" file "/tmp/file_edit_with_content_change_updates_timestamp" do action :edit block do |content| - content[0 .. -1] = "Hello, world" + content.gsub!('world', 'Itamae') end end From 4a02e9aa7fd87d76b33ce82dafbffd9235e77400 Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Tue, 10 May 2016 02:58:26 +0900 Subject: [PATCH 6/8] Don't repeat file path. --- spec/integration/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 00811d39..0f3a3aea 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -450,7 +450,7 @@ ### -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" +execute "f=/tmp/file_without_content_change_keeping_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-01T12:34:56 $f" file "/tmp/file_without_content_change_keeping_timestamp" do content "Hello, world\n" From 1ebf3cfe2b49ac04be75b6762b3a230c02431ed0 Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Tue, 10 May 2016 03:17:04 +0900 Subject: [PATCH 7/8] Fix for DigitalOcean provider. In Vagrantfile, VirtualBox provider section emulates DigitalOcean provider timezone. --- spec/integration/Vagrantfile | 2 ++ spec/integration/recipes/default.rb | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/integration/Vagrantfile b/spec/integration/Vagrantfile index e663a73f..587e47c9 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 diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 0f3a3aea..cf3dfcc1 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -402,7 +402,7 @@ ### -execute "f=/tmp/file_edit_with_content_change_updates_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-02T01:23:45 $f" +execute "f=/tmp/file_edit_with_content_change_updates_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-02T01:23:45Z $f" file "/tmp/file_edit_with_content_change_updates_timestamp" do action :edit @@ -413,7 +413,7 @@ ### -execute "touch -d 2016-05-02T12:34:56 /tmp/file_edit_without_content_change_keeping_timestamp" +execute "touch -d 2016-05-02T12:34:56Z /tmp/file_edit_without_content_change_keeping_timestamp" file "/tmp/file_edit_without_content_change_keeping_timestamp" do action :edit @@ -442,7 +442,7 @@ ### -execute "touch -d 2016-05-01T01:23:45 /tmp/file_with_content_change_updates_timestamp" +execute "touch -d 2016-05-01T01:23:45Z /tmp/file_with_content_change_updates_timestamp" file "/tmp/file_with_content_change_updates_timestamp" do content "Hello, world" @@ -450,7 +450,7 @@ ### -execute "f=/tmp/file_without_content_change_keeping_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-01T12:34:56 $f" +execute "f=/tmp/file_without_content_change_keeping_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-01T12:34:56Z $f" file "/tmp/file_without_content_change_keeping_timestamp" do content "Hello, world\n" From 27381382501fd8bb0226d208153cf3fc2ddb906b Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Tue, 17 May 2016 19:11:11 +0900 Subject: [PATCH 8/8] Fix code flow on action_edit method. * From https://github.com/itamae-kitchen/itamae/pull/212#issuecomment-219426461 --- lib/itamae/resource/file.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/itamae/resource/file.rb b/lib/itamae/resource/file.rb index d9385232..1953453c 100644 --- a/lib/itamae/resource/file.rb +++ b/lib/itamae/resource/file.rb @@ -86,20 +86,15 @@ def action_delete(options) def action_edit(options) change_target = attributes.modified ? @temppath : attributes.path - if attributes.mode - run_specinfra(:change_file_mode, change_target, attributes.mode) - else - mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp + 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 - 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, change_target, owner) - run_specinfra(:change_file_group, change_target, group) + 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