opscode/chef — pull request #1546 by jmink (2014-06-24 20:58:21+00:00)
Title: CHEF-3960 Symlinks to directories should be swingable

Currently if a symlink exists to a directory and a recipe attempts to swing it to a new directory there is an error on Windows. Desired behavior is an error for swinging from a directory to a file, but not from a directory to a directory.

I tested this by creating two directories, A and AA, then running the following recipes using chef-apply on both windows:

link 'C:\dev\Temp\B' do
to 'C:\dev\Temp\A'
link_type :symbolic
end

link 'C:\dev\Temp\B' do
to 'C:\dev\Temp\AA'
link_type :symbolic
end

I also added a functional test and ran that from the windows VM as well as locally.

I don't like where the change is. It'd be cleaner to have it in lib/chef/provider/file.rb, however the dir -> file case would still have to be special cased in link.rb negating a lot of the advantage and the code would have to exist in the windows specific file handler as well. It's also throwing permission errors when I try and move the code into file.rb for reasons I don't understand. I'm also worried by the comment in file.rb/unlink that directories can not be unlinked. Testing didn't reveal any issues with calling ::Dir.unlink, but it may be a corner case on an OS I didn't test.

@opscode/client-eng