diff options
author | Sean Horn <sean_horn@opscode.com> | 2014-01-17 15:34:51 -0500 |
---|---|---|
committer | Sean Horn <sean_horn@opscode.com> | 2014-01-17 15:34:51 -0500 |
commit | 8fa3eb345e75ff56595fae7c6eb28d130e45af2d (patch) | |
tree | 307d8d9d5316ddbc9911e855c6c7aaab439a8676 | |
parent | 379d177da06b6886ac5bfe677e5ebb2e039c2e2c (diff) | |
download | chef-sh/remote_file_local_source_10-stable.tar.gz |
[HelpSpot 16643] Allow 10-stable to source local remote_filesh/remote_file_local_source_10-stable
-rw-r--r-- | chef/lib/chef/provider/remote_file.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/chef/lib/chef/provider/remote_file.rb b/chef/lib/chef/provider/remote_file.rb index 9ba1297001..d3709b6f67 100644 --- a/chef/lib/chef/provider/remote_file.rb +++ b/chef/lib/chef/provider/remote_file.rb @@ -37,8 +37,13 @@ class Chef if current_resource_matches_target_checksum? Chef::Log.debug("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating") else - rest = Chef::REST.new(@new_resource.source, nil, nil, http_client_opts) - raw_file = rest.streaming_request(rest.create_url(@new_resource.source), {}) + fileuri = URI.parse(@new_resource.source) + if local_file?(fileuri) + raw_file = read_local_file(fileuri) + else + rest = Chef::REST.new(@new_resource.source, nil, nil, http_client_opts) + raw_file = rest.streaming_request(rest.create_url(@new_resource.source), {}) + end if matches_current_checksum?(raw_file) Chef::Log.debug "#{@new_resource} target and source checksums are the same - not updating" else @@ -65,6 +70,16 @@ class Chef @new_resource.checksum && @current_resource.checksum && @current_resource.checksum =~ /^#{Regexp.escape(@new_resource.checksum)}/ end + def local_file?(uri) + true if uri.scheme == "file" + end + + def read_local_file(uri) + tf = Tempfile.open("chef-rest") + ::File.open(uri.path, "rb") {|io| tf << io.read} + tf.close + end + def matches_current_checksum?(candidate_file) Chef::Log.debug "#{@new_resource} checking for file existence of #{@new_resource.path}" if ::File.exists?(@new_resource.path) |