Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
remote file uses cookbook file for cookbook files/*
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Jun 3, 2010
1 parent 7d58ea9 commit 8299049
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion chef/lib/chef/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions chef/lib/chef/resource/remote_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions chef/spec/unit/resource/remote_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8299049

Please sign in to comment.