Skip to content

Commit 701e2ae

Browse files
author
Nuo Yan
committed
fixed CHEF-195(file.rb, file_spec.rb)
1 parent 027c94e commit 701e2ae

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

chef/lib/chef/provider/file.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def action_touch
159159

160160
def backup(file=nil)
161161
file ||= @new_resource.path
162-
if @new_resource.backup >0 && ::File.exist?(file)
162+
if @new_resource.backup > 0 && ::File.exist?(file)
163163
time = Time.now
164164
savetime = time.strftime("%Y%m%d%H%M%S")
165165
backup_filename = "#{@new_resource.path}.chef-#{savetime}"
@@ -176,7 +176,6 @@ def backup(file=nil)
176176
FileUtils.rm(backup_to_delete)
177177
end
178178
end
179-
180179
end
181180
end
182181

chef/spec/unit/provider/file_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,16 @@
220220
File.stub!(:exist?).and_return(true)
221221
@provider.backup
222222
end
223-
223+
224+
it "should not attempt to backup a file if :backup == 0" do
225+
@provider.load_current_resource
226+
@provider.new_resource.stub!(:path).and_return("/tmp/s-20080705111233")
227+
@provider.new_resource.stub!(:backup).and_return(0)
228+
FileUtils.stub!(:cp).and_return(true)
229+
File.stub!(:exist?).and_return(true)
230+
FileUtils.should_not_receive(:cp)
231+
@provider.backup
232+
end
224233
end
225234

226235
describe Chef::Provider::File, "action_create_if_missing" do
@@ -236,4 +245,4 @@
236245
@provider.should_receive(:action_create).and_return(true)
237246
@provider.action_create_if_missing
238247
end
239-
end
248+
end

0 commit comments

Comments
 (0)