summaryrefslogtreecommitdiff
path: root/lib/chef/provider/remote_file/ftp.rb
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-13 18:03:41 -0500
committerJesse Campbell <hikeit@gmail.com>2013-02-13 18:03:41 -0500
commit5353ca7686bf34d88225a827c9f4b5cca473be37 (patch)
tree397e35af2ea26c0f1a4f022f8dac63b1897e7a53 /lib/chef/provider/remote_file/ftp.rb
parent1aa762b1889a7ba70db1f99029293d5c8d85b388 (diff)
downloadchef-5353ca7686bf34d88225a827c9f4b5cca473be37.tar.gz
move dir parsing out of ftp.initialize, don't overwrite
new_resource.source
Diffstat (limited to 'lib/chef/provider/remote_file/ftp.rb')
-rw-r--r--lib/chef/provider/remote_file/ftp.rb27
1 files changed, 16 insertions, 11 deletions
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)