summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-03-01 11:11:05 -0500
committerJesse Campbell <hikeit@gmail.com>2013-03-01 11:11:05 -0500
commit2139a6888756fdcedce559c9e38a8ea76a5f7b54 (patch)
tree480cebfe3c81d4b231800f869014afd99ae58f47 /lib/chef
parent574d77db45f170e4c8297bfda2609a7eb7bed42b (diff)
downloadchef-2139a6888756fdcedce559c9e38a8ea76a5f7b54.tar.gz
strip target_matched, use tempfile=nil instead
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/remote_file.rb18
-rw-r--r--lib/chef/provider/remote_file/ftp.rb4
-rw-r--r--lib/chef/provider/remote_file/http.rb7
-rw-r--r--lib/chef/provider/remote_file/local_file.rb24
4 files changed, 24 insertions, 29 deletions
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
index 01b06e6bd3..66e8fcccf6 100644
--- a/lib/chef/provider/remote_file.rb
+++ b/lib/chef/provider/remote_file.rb
@@ -46,8 +46,8 @@ class Chef
Chef::Log.debug("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating")
else
sources = @new_resource.source
- raw_file, raw_file_source, target_matched = try_multiple_sources(sources)
- if target_matched
+ raw_file, raw_file_source = try_multiple_sources(sources)
+ if raw_file.nil?
Chef::Log.info("#{@new_resource} matched #{raw_file_source}, not updating")
elsif matches_current_checksum?(raw_file)
Chef::Log.info("#{@new_resource} downloaded from #{raw_file_source}, checksums match, not updating")
@@ -109,7 +109,7 @@ class Chef
source = sources.shift
begin
uri = URI.parse(source)
- raw_file, target_matched = grab_file_from_uri(uri)
+ raw_file = grab_file_from_uri(uri)
rescue ArgumentError => e
raise e
rescue => e
@@ -129,7 +129,7 @@ class Chef
if uri.userinfo
uri.password = "********"
end
- return raw_file, uri.to_s, target_matched
+ return raw_file, uri.to_s
end
# Given a source uri, return a Tempfile, or a File that acts like a Tempfile (close! method)
@@ -146,23 +146,23 @@ class Chef
end
if URI::HTTP === uri
#HTTP or HTTPS
- raw_file, mtime, etag, target_matched = HTTP::fetch(uri, proxy_uri(uri), if_modified_since, if_none_match)
+ raw_file, mtime, etag = HTTP::fetch(uri, proxy_uri(uri), if_modified_since, if_none_match)
elsif URI::FTP === uri
#FTP
- raw_file, mtime, target_matched = FTP::fetch(uri, proxy_uri(uri), @new_resource.ftp_active_mode, if_modified_since)
+ raw_file, mtime = FTP::fetch(uri, proxy_uri(uri), @new_resource.ftp_active_mode, if_modified_since)
etag = nil
elsif uri.scheme == "file"
#local/network file
- raw_file, mtime, target_matched = LocalFile::fetch(uri, if_modified_since)
+ raw_file, mtime = LocalFile::fetch(uri, if_modified_since)
etag = nil
else
raise ArgumentError, "Invalid uri. Only http(s), ftp, and file are currently supported"
end
- unless target_matched
+ unless raw_file.nil?
@new_resource.etag etag unless @new_resource.etag
@new_resource.last_modified mtime unless @new_resource.last_modified
end
- return raw_file, target_matched
+ return raw_file
end
#adapted from buildr/lib/buildr/core/transports.rb via chef/rest/rest_client.rb
diff --git a/lib/chef/provider/remote_file/ftp.rb b/lib/chef/provider/remote_file/ftp.rb
index 20526324d1..cb06766bb3 100644
--- a/lib/chef/provider/remote_file/ftp.rb
+++ b/lib/chef/provider/remote_file/ftp.rb
@@ -32,13 +32,11 @@ class Chef
mtime = ftp.mtime
if mtime && last_modified && mtime.to_i <= last_modified.to_i
tempfile = nil
- target_matched = true
else
tempfile = ftp.fetch
- target_matched = false
end
ftp.disconnect
- return tempfile, mtime, target_matched
+ return tempfile, mtime
end
# Parse the uri into instance variables
diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb
index 8bf7238baa..157f4f3291 100644
--- a/lib/chef/provider/remote_file/http.rb
+++ b/lib/chef/provider/remote_file/http.rb
@@ -46,8 +46,7 @@ class Chef
def execute
begin
rest = RestClient::Request.execute(:method => :get, :url => @uri.to_s, :headers => @headers, :raw_response => true)
- raw_file = rest.file
- target_matched = false
+ tempfile = rest.file
if rest.headers.include?(:last_modified)
mtime = Time.parse(rest.headers[:last_modified])
elsif rest.headers.include?(:date)
@@ -62,12 +61,12 @@ class Chef
end
rescue RestClient::Exception => e
if e.http_code == 304
- target_matched = true
+ tempfile = nil
else
raise e
end
end
- return raw_file, mtime, etag, target_matched
+ return tempfile, mtime, etag
end
end
diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb
index e9df6aa216..346867348d 100644
--- a/lib/chef/provider/remote_file/local_file.rb
+++ b/lib/chef/provider/remote_file/local_file.rb
@@ -23,22 +23,20 @@ require 'chef/provider/remote_file'
class Chef
class Provider
class RemoteFile
- class LocalFile < ::File
+ class LocalFile
# Fetches the file at uri, returning a Tempfile-like File handle
def self.fetch(uri, if_modified_since)
- raw_file = LocalFile.new(uri.path)
- mtime = raw_file.mtime
- target_matched = mtime && if_modified_since && mtime.to_i <= if_modified_since.to_i
- if target_matched
- raw_file.close
- raw_file = nil
- end
- return raw_file, mtime, target_matched
- end
-
- def close!
- close
+ mtime = ::File.mtime(uri.path)
+ if mtime && if_modified_since && mtime.to_i <= if_modified_since.to_i
+ tempfile = nil
+ else
+ tempfile = Tempfile.new(File.basename(uri.path))
+ Chef::Log.debug("#{@new_resource} staging #{uri.path} to #{tempfile.path}")
+ FileUtils.cp(uri.path, tempfile.path)
+ tempfile
+ end
+ return tempfile, mtime
end
end