Permalink
Browse files

remote file uses cookbook file for cookbook files/*

  • Loading branch information...
1 parent 7d58ea9 commit 82990490b788c51b5f25610db5aa6d8f22307be6 @danielsdeleo danielsdeleo committed May 25, 2010
Showing with 35 additions and 1 deletion.
  1. +0 −1 chef/lib/chef/platform.rb
  2. +23 −0 chef/lib/chef/resource/remote_file.rb
  3. +12 −0 chef/spec/unit/resource/remote_file_spec.rb
@@ -162,7 +162,6 @@ def platforms
:directory => Chef::Provider::Directory,
:link => Chef::Provider::Link,
:template => Chef::Provider::Template,
- :remote_file => Chef::Provider::RemoteFile,
:remote_directory => Chef::Provider::RemoteDirectory,
:execute => Chef::Provider::Execute,
:mount => Chef::Provider::Mount::Mount,
@@ -54,6 +54,29 @@ def checksum(args=nil)
)
end
+ # The provider that should be used for this resource.
+ # === Returns:
+ # Chef::Provider::RemoteFile when the source is an absolute URI, like
+ # http://www.google.com/robots.txt
+ # Chef::Provider::CookbookFile when the source is a relative URI, like
+ # 'myscript.pl', 'dir/config.conf'
+ def provider
+ if absolute_uri?(source)
+ Chef::Provider::RemoteFile
+ else
+ # contentious...
+ Chef::Log.warn("remote_file is deprecated for fetching files from cookbooks. Use cookbook_file instead")
+ Chef::Provider::CookbookFile
+ end
+ end
+
+ private
+
+ def absolute_uri?(source)
+ URI.parse(source).absolute?
+ rescue URI::InvalidURIError
+ false
+ end
end
end
@@ -32,6 +32,18 @@
end
end
+ it "says its provider is RemoteFile when the source is an absolute URI" do
+ @resource.source("http://www.google.com/robots.txt")
+ @resource.provider.should == Chef::Provider::RemoteFile
+ Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::RemoteFile
+ end
+
+ it "says its provider is CookbookFile when the source is a relative URI" do
+ @resource.source('seattle.txt')
+ @resource.provider.should == Chef::Provider::CookbookFile
+ Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::CookbookFile
+ end
+
describe "source" do
it "should accept a string for the remote file source" do
@resource.source "something"

0 comments on commit 8299049

Please sign in to comment.