<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,9 +6,9 @@
 # Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 #     http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,14 +26,14 @@ require 'net/https'
 class Chef
   class Provider
     class RemoteFile &lt; Chef::Provider::File
-      
+
       include Chef::Mixin::FindPreferredFile
-      
-      def action_create        
+
+      def action_create
         Chef::Log.debug(&quot;Checking #{@new_resource} for changes&quot;)
         do_remote_file(@new_resource.source, @current_resource.path)
       end
-      
+
       def action_create_if_missing
         if ::File.exists?(@new_resource.path)
           Chef::Log.debug(&quot;File #{@new_resource.path} exists, taking no action.&quot;)
@@ -41,56 +41,28 @@ class Chef
           action_create
         end
       end
-    
+
       def do_remote_file(source, path)
-        # The remote filehandle
-        raw_file = nil
-        
         # The current files checksum
-        current_checksum = nil
         current_checksum = self.checksum(path) if ::File.exists?(path)
-        
-        # If we are solo, try and find the file in a local cookbook
-        #  assuming we find it, we open it up and set it to raw_file.
-        if Chef::Config[:solo]
-          filename = find_preferred_file(
-            @new_resource.cookbook_name.to_s,
-            :remote_file,
-            source,
-            @node[:fqdn],
-            @node[:platform],
-            @node[:platform_version]
-          )
-          Chef::Log.debug(&quot;Using local file for remote_file:#{filename}&quot;)
-          raw_file = ::File.open(filename)
-        else
-        # Otherwise, we need to go get it from the chef server
-        # This results in a tmpfile as raw_file
-          r = Chef::REST.new(Chef::Config[:remotefile_url])
-          
-          url = generate_url(
-            source, 
-            &quot;files&quot;, 
-            { 
-              :checksum =&gt; current_checksum
-            }
-          )
-          
-          begin
-            raw_file = r.get_rest(url, true)
-          rescue Net::HTTPRetriableError =&gt; e
-            if e.response.kind_of?(Net::HTTPNotModified)
-              Chef::Log.debug(&quot;File #{path} is unchanged&quot;)
-              return false
-            else
-              raise e
-            end
+
+        begin
+          # The remote filehandle
+          raw_file = get_from_uri(source)    ||
+                     get_from_server(source, current_checksum) ||
+                     get_from_local_cookbook(source)
+        rescue Net::HTTPRetriableError =&gt; e
+          if e.response.kind_of?(Net::HTTPNotModified)
+            Chef::Log.debug(&quot;File #{path} is unchanged&quot;)
+            return false
+          else
+            raise e
           end
         end
-      
+
         # If the file exists
         if ::File.exists?(@new_resource.path)
-          # And it matches the checsum of the raw file
+          # And it matches the checksum of the raw file
           @new_resource.checksum(self.checksum(raw_file.path))
           if @new_resource.checksum != @current_resource.checksum
             # Updating target file, let's perform a backup!
@@ -102,17 +74,48 @@ class Chef
           # We're creating a new file
           Chef::Log.info(&quot;Creating #{@new_resource} at #{@new_resource.path}&quot;)
         end
-      
+
         FileUtils.cp(raw_file.path, @new_resource.path)
         @new_resource.updated = true
 
-        set_owner if @new_resource.owner != nil
-        set_group if @new_resource.group != nil
-        set_mode if @new_resource.mode != nil
+        set_owner if @new_resource.owner
+        set_group if @new_resource.group
+        set_mode  if @new_resource.mode
 
-        return true
+        true
       end
-      
+
+      def get_from_uri(source)
+        uri = URI.parse(source)
+        if uri.absolute
+          r = Chef::REST.new(source)
+          r.get_rest(source, true)
+        end
+      rescue URI::InvalidURIError
+        nil
+      end
+
+      def get_from_server(source, current_checksum)
+        unless Chef::Config[:solo]
+          r = Chef::REST.new(Chef::Config[:remotefile_url])
+          url = generate_url(source, &quot;files&quot;, :checksum =&gt; current_checksum)
+          r.get_rest(url, true)
+        end
+      end
+
+      def get_from_local_cookbook(source)
+        filename = find_preferred_file(
+          @new_resource.cookbook_name.to_s,
+          :remote_file,
+          source,
+          @node[:fqdn],
+          @node[:platform],
+          @node[:platform_version]
+        )
+        Chef::Log.debug(&quot;Using local file for remote_file:#{filename}&quot;)
+        ::File.open(filename)
+      end
+
     end
   end
 end</diff>
      <filename>chef/lib/chef/provider/remote_file.rb</filename>
    </modified>
    <modified>
      <diff>@@ -61,7 +61,41 @@ describe Chef::Provider::RemoteFile, &quot;do_remote_file&quot; do
     Chef::REST.stub!(:new).and_return(@rest)    
     @provider.do_remote_file(@resource.source, @resource.path)
   end
+
+  describe &quot;when given a URI source&quot; do
+    it &quot;should download the file from the remote URL&quot; do
+      @resource.source(&quot;http://opscode.com/seattle.txt&quot;)
+      @rest.should_receive(:get_rest).with(&quot;http://opscode.com/seattle.txt&quot;, true).and_return(@tempfile)
+      do_remote_file
+    end
+  end
   
+  describe &quot;when given a non-URI source&quot; do
+    describe &quot;and using chef-solo&quot; do
+      it &quot;should load the file from the local cookbook&quot; do
+        Chef::Config[:solo] = true
+        File.stub!(:open).and_return(@tempfile)
+        @provider.should_receive(:find_preferred_file).with(&quot;monkey&quot;, :remote_file, @resource.source, &quot;latte.local&quot;, nil, nil).and_return(@tempfile.path)
+        do_remote_file
+      end
+    end
+    
+    it &quot;should call generate_url with the current checksum as an extra attribute&quot; do
+      @provider.should_receive(:generate_url).with(@resource.source, &quot;files&quot;, { :checksum =&gt; &quot;0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa&quot;})
+      do_remote_file
+    end
+
+    it &quot;should call get_rest with a correctly composed url&quot; do
+      url = &quot;cookbooks/#{@resource.cookbook_name}/files?id=#{@resource.source}&quot;
+      url += &quot;&amp;platform=mac_os_x&quot;
+      url += &quot;&amp;version=10.5.1&quot;
+      url += &quot;&amp;fqdn=latte.local&quot;
+      url += &quot;&amp;checksum=0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa&quot;
+      @rest.should_receive(:get_rest).with(url, true).and_return(@tempfile)
+      do_remote_file
+    end
+  end
+
   it &quot;should set the checksum if the file exists&quot; do
     @provider.should_receive(:checksum).with(@resource.path)
     do_remote_file
@@ -72,22 +106,7 @@ describe Chef::Provider::RemoteFile, &quot;do_remote_file&quot; do
     @provider.should_not_receive(:checksum).with(@resource.path)
     do_remote_file
   end
-  
-  it &quot;should call generate_url with the current checksum as an extra attribute&quot; do
-    @provider.should_receive(:generate_url).with(@resource.source, &quot;files&quot;, { :checksum =&gt; &quot;0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa&quot;})
-    do_remote_file
-  end
-  
-  it &quot;should call get_rest with a correctly composed url&quot; do
-    url = &quot;cookbooks/#{@resource.cookbook_name}/files?id=#{@resource.source}&quot;
-    url += &quot;&amp;platform=mac_os_x&quot;
-    url += &quot;&amp;version=10.5.1&quot;
-    url += &quot;&amp;fqdn=latte.local&quot;
-    url += &quot;&amp;checksum=0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa&quot;
-    @rest.should_receive(:get_rest).with(url, true).and_return(@tempfile)
-    do_remote_file
-  end
-  
+    
   it &quot;should not transfer the file if it has not been changed&quot; do
     r = Net::HTTPNotModified.new(&quot;one&quot;, &quot;two&quot;, &quot;three&quot;)
     e = Net::HTTPRetriableError.new(&quot;304&quot;, r)
@@ -117,6 +136,7 @@ describe Chef::Provider::RemoteFile, &quot;do_remote_file&quot; do
   describe &quot;when the target file already exists&quot; do
     before do
       ::File.stub!(:exists?).and_return(true)
+      @provider.stub!(:get_from_server).and_return(@tempfile)
     end
 
     it &quot;should backup the original file if it is different&quot; do</diff>
      <filename>chef/spec/unit/provider/remote_file_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bbc71e1463c42f7d4ef7bca680c5d333f07029ff</id>
    </parent>
  </parents>
  <author>
    <name>Sean Cribbs</name>
    <email>seancribbs@gmail.com</email>
  </author>
  <url>http://github.com/opscode/chef/commit/a831499a6f402ca95b8e1152bc913d324eea3199</url>
  <id>a831499a6f402ca95b8e1152bc913d324eea3199</id>
  <committed-date>2009-02-06T06:55:51-08:00</committed-date>
  <authored-date>2009-02-05T06:39:57-08:00</authored-date>
  <message>CHEF-89: Refactor Chef::Provider::RemoteFile to support downloads from any URI.</message>
  <tree>959f39a281c8fdfae75f5548dcda721d93810866</tree>
  <committer>
    <name>Sean Cribbs</name>
    <email>seancribbs@gmail.com</email>
  </committer>
</commit>
