Skip to content

Commit 61edf38

Browse files
committed
Match also partial checksums so we don't have to type the whole thing out
1 parent 766a83a commit 61edf38

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

chef/lib/chef/provider/remote_file.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def do_remote_file(source, path)
4646
# The current files checksum
4747
current_checksum = self.checksum(path) if ::File.exists?(path)
4848

49-
unless (@new_resource.checksum && @new_resource.checksum == current_checksum)
49+
if(@new_resource.checksum && current_checksum && current_checksum =~ /^#{@new_resource.checksum}/)
50+
Chef::Log.debug("File #{@new_resource} checksum matches, not updating")
51+
else
5052
begin
5153
# The remote filehandle
5254
raw_file = get_from_uri(source) ||
@@ -82,8 +84,6 @@ def do_remote_file(source, path)
8284
# We're done with the file, so make sure to close it if it was open.
8385
raw_file.close
8486
true
85-
else
86-
Chef::Log.debug("File #{@new_resource} checksum matches, not updating")
8787
end
8888

8989
set_owner if @new_resource.owner

chef/spec/unit/provider/remote_file_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,29 @@ def do_remote_file
7373
do_remote_file
7474
end
7575

76-
it "should download the file if the checksum matches" do
76+
it "should not download the file if the checksum is a partial match from the beginning" do
77+
@resource.checksum("0fd012fd")
78+
@resource.source("http://opscode.com/seattle.txt")
79+
@rest.should_not_receive(:get_rest).with("http://opscode.com/seattle.txt", true).and_return(@tempfile)
80+
do_remote_file
81+
end
82+
83+
84+
it "should download the file if the checksum does not match" do
7785
@resource.checksum("this hash doesn't match")
7886
@resource.source("http://opscode.com/seattle.txt")
7987
@rest.should_receive(:get_rest).with("http://opscode.com/seattle.txt", true).and_return(@tempfile)
8088
do_remote_file
8189
end
90+
91+
it "should download the file if the checksum matches, but not from the beginning" do
92+
@resource.checksum("fd012fd")
93+
@resource.source("http://opscode.com/seattle.txt")
94+
@rest.should_receive(:get_rest).with("http://opscode.com/seattle.txt", true).and_return(@tempfile)
95+
do_remote_file
96+
end
97+
98+
8299
end
83100

84101
describe "and not given a checksum" do

0 commit comments

Comments
 (0)