Skip to content

Commit 282d473

Browse files
author
chris
committed
Fixing CHEF-185: action_delete does not backup symlinks
1 parent 2b8c1f2 commit 282d473

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

chef/lib/chef/provider/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def action_create_if_missing
140140

141141
def action_delete
142142
if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path)
143-
backup
143+
backup unless ::File.symlink?(@new_resource.path)
144144
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
145145
::File.delete(@new_resource.path)
146146
@new_resource.updated = true

chef/spec/unit/provider/file_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@
6565
provider.current_resource.group.should eql(nil)
6666
provider.current_resource.mode.should eql(nil)
6767
end
68+
69+
it "should not backup symbolic links on delete" do
70+
path = File.join(File.dirname(__FILE__), "..", "..", "data", "detroit.txt")
71+
::File.open(path, "w") do |file|
72+
file.write("Detroit's not so nice, so you should come to Seattle instead and buy me a beer instead.")
73+
end
74+
@resource = Chef::Resource::File.new("detroit")
75+
@resource.path(path)
76+
@node = Chef::Node.new
77+
@node.name "latte"
78+
@provider = Chef::Provider::File.new(@node, @resource)
79+
80+
::File.stub!(:symlink?).and_return(true)
81+
@provider.should_not_receive(:backup)
82+
@provider.action_delete
83+
end
6884

6985
it "should load the correct value for owner of the current resource" do
7086
stats = File.stat(@resource.path)
@@ -236,4 +252,4 @@
236252
@provider.should_receive(:action_create).and_return(true)
237253
@provider.action_create_if_missing
238254
end
239-
end
255+
end

0 commit comments

Comments
 (0)