summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2012-10-25 00:33:40 -0700
committerBryan McLellan <btm@opscode.com>2012-10-25 16:40:48 -0700
commit09494314ae792fb93bf99e4361331ee096b04be5 (patch)
tree13f0e13e56e6c1857bbbbae6e6840fd63a17647f
parent2ac4e2d6b5737ccfa00306432d9f41e294ed7e6a (diff)
downloadchef-09494314ae792fb93bf99e4361331ee096b04be5.tar.gz
[CHEF-3552] Enable whyrun support for remote_directory provider.
The remote_directory provider calls functions from the directory provider which is whyrun enabled. This results in the state-changing actions(namely mkdir) in Chef::Provider::Directory#action_create to actually be called *after* the actions in the Chef::Provider::RemoteDirecotry#action_create function, even if super is called at the beginning of the latter function.
-rw-r--r--chef/lib/chef/provider/remote_directory.rb39
-rw-r--r--chef/spec/unit/provider/remote_directory_spec.rb7
2 files changed, 31 insertions, 15 deletions
diff --git a/chef/lib/chef/provider/remote_directory.rb b/chef/lib/chef/provider/remote_directory.rb
index 9ccd7ea056..dee383f763 100644
--- a/chef/lib/chef/provider/remote_directory.rb
+++ b/chef/lib/chef/provider/remote_directory.rb
@@ -34,23 +34,27 @@ class Chef
def action_create
super
-
- files_to_purge = Set.new(
- Dir.glob(::File.join(@new_resource.path, '**', '*'), ::File::FNM_DOTMATCH).select do |name|
- name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/
- end
- )
- files_to_transfer.each do |cookbook_file_relative_path|
- create_cookbook_file(cookbook_file_relative_path)
- # the file is removed from the purge list
- files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
- # parent directories are also removed from the purge list
- directories=::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)).split(::File::SEPARATOR)
- for i in 0..directories.length-1
- files_to_purge.delete(::File.join(directories[0..i]))
+ files_to_purge = Set.new(Dir.glob(::File.join(@new_resource.path, '**', '*'),
+ ::File::FNM_DOTMATCH).select do |name|
+ name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/
+ end)
+
+ converge_by("Create managed files in directory") do
+ files_to_transfer.each do |cookbook_file_relative_path|
+ create_cookbook_file(cookbook_file_relative_path)
+ # the file is removed from the purge list
+ files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
+ # parent directories are also removed from the purge list
+ directories=::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)).split(::File::SEPARATOR)
+ for i in 0..directories.length-1
+ files_to_purge.delete(::File.join(directories[0..i]))
+ end
end
end
- purge_unmanaged_files(files_to_purge)
+
+ converge_by("Purge unmanaged files from directory") do
+ purge_unmanaged_files(files_to_purge)
+ end
end
def action_create_if_missing
@@ -170,5 +174,10 @@ class Chef
end
end
+
+ def whyrun_supported?
+ true
+ end
+
end
end
diff --git a/chef/spec/unit/provider/remote_directory_spec.rb b/chef/spec/unit/provider/remote_directory_spec.rb
index eb5c372304..3a7838edc5 100644
--- a/chef/spec/unit/provider/remote_directory_spec.rb
+++ b/chef/spec/unit/provider/remote_directory_spec.rb
@@ -98,6 +98,13 @@ describe Chef::Provider::RemoteDirectory do
after {FileUtils.rm_rf(@destination_dir)}
+ # CHEF-3552
+ it "creates the toplevel directory without error " do
+ @resource.recursive(false)
+ @provider.run_action(:create)
+ ::File.exist?(@destination_dir).should be_true
+ end
+
it "transfers the directory with all contents" do
@provider.run_action(:create)
::File.exist?(@destination_dir + '/remote_dir_file1.txt').should be_true