Permalink
Browse files

fix remote_directory to remove symlinked directories correctly with t…

…he purge option
  • Loading branch information...
1 parent ec9c188 commit d30192dbea5ab3a2b9764ffa5b51dcebe105fb76 @jakedouglas committed Jan 31, 2012
Showing with 16 additions and 1 deletion.
  1. +1 −1 chef/lib/chef/provider/remote_directory.rb
  2. +15 −0 chef/spec/unit/provider/remote_directory_spec.rb
@@ -57,7 +57,7 @@ def action_create_if_missing
def purge_unmanaged_files(unmanaged_files)
if @new_resource.purge
unmanaged_files.sort.reverse.each do |f|
- if ::File.directory?(f)
+ if ::File.directory?(f) && !::File.symlink?(f)
Dir::rmdir(f)
Chef::Log.debug("#{@new_resource} removed directory #{f}")
else
@@ -128,6 +128,21 @@
::File.exist?(@destination_dir + '/a/multiply/nested/baz.txt').should be_false
::File.exist?(@destination_dir + '/a/multiply/nested/directory/qux.txt').should be_false
end
+
+ it "removes directory symlinks properly" do
+ symlinked_dir_path = @destination_dir + '/symlinked_dir'
+ @provider.action_create
+
+ Dir.mktmpdir do |tmp_dir|
+ FileUtils.ln_s(tmp_dir, symlinked_dir_path)
+ ::File.exist?(symlinked_dir_path).should be_true
+
+ @provider.action_create
+
+ ::File.exist?(symlinked_dir_path).should be_false
+ ::File.exist?(tmp_dir).should be_true
+ end
+ end
end
describe "with overwrite disabled" do

0 comments on commit d30192d

Please sign in to comment.