summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-13 18:03:41 -0500
committerBryan McLellan <btm@opscode.com>2013-02-26 11:11:44 -0800
commit77fed4d37369e92cca423efdef7b1a72a18a190f (patch)
tree907979d0f442d106424bbb47ad9e98e02ebeb578
parentaa4235dbd8b0d40d9fea29f75f3ba35e01ef0c43 (diff)
downloadchef-77fed4d37369e92cca423efdef7b1a72a18a190f.tar.gz
move dir parsing out of ftp.initialize, don't overwrite
new_resource.source
-rw-r--r--lib/chef/provider/remote_file.rb10
-rw-r--r--lib/chef/provider/remote_file/ftp.rb27
2 files changed, 21 insertions, 16 deletions
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
index 82ccec76c7..4d1e696d0e 100644
--- a/lib/chef/provider/remote_file.rb
+++ b/lib/chef/provider/remote_file.rb
@@ -1,6 +1,6 @@
#
-# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Jesse Campbell (<hikeit@gmail.com>)
+# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -40,12 +40,12 @@ class Chef
Chef::Log.debug("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating")
else
sources = @new_resource.source
- raw_file = try_multiple_sources(sources)
+ raw_file, raw_file_source = try_multiple_sources(sources)
if matches_current_checksum?(raw_file)
Chef::Log.debug "#{@new_resource} target and source checksums are the same - not updating"
else
description = []
- description << "copy file downloaded from #{@new_resource.source} into #{@new_resource.path}"
+ description << "copy file downloaded from #{raw_file_source} into #{@new_resource.path}"
description << diff_current(raw_file.path)
converge_by(description) do
backup_new_resource
@@ -94,6 +94,7 @@ class Chef
# Given an array of source uris, iterate through them until one does not fail
def try_multiple_sources(sources)
+ sources = sources.dup
source = sources.shift
begin
uri = URI.parse(source)
@@ -117,8 +118,7 @@ class Chef
if uri.userinfo
uri.password = "********"
end
- @new_resource.source uri.to_s
- raw_file
+ return raw_file, uri.to_s
end
# Given a source uri, return a Tempfile, or a File that acts like a Tempfile (close! method)
diff --git a/lib/chef/provider/remote_file/ftp.rb b/lib/chef/provider/remote_file/ftp.rb
index d2ebbc5faa..3b142dcd93 100644
--- a/lib/chef/provider/remote_file/ftp.rb
+++ b/lib/chef/provider/remote_file/ftp.rb
@@ -33,17 +33,7 @@ class Chef
# Parse the uri into instance variables
def initialize(uri, ftp_active_mode)
- @path = uri.path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.
- @directories = @path.split(%r{/}, -1)
- @directories.each {|d|
- d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") }
- }
- unless @filename = @directories.pop
- raise ArgumentError, "no filename: #{uri.inspect}"
- end
- if @filename.length == 0 || @filename.end_with?( "/" )
- raise ArgumentError, "no filename: #{uri.inspect}"
- end
+ @directories, @filename = parse_path(uri.path)
@typecode = uri.typecode
# Only support ascii and binary types
if @typecode && /\A[ai]\z/ !~ @typecode
@@ -61,6 +51,21 @@ class Chef
end
end
+ def parse_path(path)
+ path = path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.
+ directories = path.split(%r{/}, -1)
+ directories.each {|d|
+ d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") }
+ }
+ unless filename = directories.pop
+ raise ArgumentError, "no filename: #{uri.inspect}"
+ end
+ if filename.length == 0 || filename.end_with?( "/" )
+ raise ArgumentError, "no filename: #{uri.inspect}"
+ end
+ return directories, filename
+ end
+
# Fetches using Net::FTP, returns a Tempfile with the content
def fetch()
tempfile = Tempfile.new(@filename)