summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-27 23:27:22 -0700
committerLuke Kanies <luke@madstop.com>2008-08-27 23:27:22 -0700
commitee1a85d61bb6ee9b31ae4881adc0c136a99e42ed (patch)
tree97cac13c651d60f6498451c85d70137bf6bb2786 /lib/puppet
parent7c68fdb46802dbd3a57f5f7be3333ed6feacad45 (diff)
downloadpuppet-ee1a85d61bb6ee9b31ae4881adc0c136a99e42ed.tar.gz
puppet-ee1a85d61bb6ee9b31ae4881adc0c136a99e42ed.tar.xz
puppet-ee1a85d61bb6ee9b31ae4881adc0c136a99e42ed.zip
Mostly finishing refactoring file recursion to use REST.
We have the majority of the work done (and it's a *lot* less code). We just have six more tests we need to implement the code for. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type/file.rb57
-rwxr-xr-xlib/puppet/type/file/source.rb10
2 files changed, 50 insertions, 17 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index bc2e53c9f..2e3a585c1 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -329,7 +329,7 @@ module Puppet
# Create any children via recursion or whatever.
def eval_generate
- recurse()
+ recurse() if self.recurse?
end
def flush
@@ -679,27 +679,54 @@ module Puppet
@parameters.include?(:purge) and (self[:purge] == :true or self[:purge] == "true")
end
+ # Recurse the target of the link.
+ def recurse_link
+ perform_recursion(self[:target])
+ end
+
+ # Recurse the file itself, returning a Metadata instance for every found file.
+ def recurse_local
+ perform_recursion(self[:path])
+ end
+
+ # Recurse against our remote file.
+ def recurse_remote
+ total = self[:source].collect do |source|
+ next unless result = perform_recursion(source)
+ result.each { |data| data.source = "%s/%s" % [source, data.relative_path] }
+ return result if result and ! result.empty? and self[:sourceselect] == :first
+ result
+ end.flatten
+
+ # This only happens if we have sourceselect == :all
+ found = []
+ total.find_all do |data|
+ result = ! found.include?(data.relative_path)
+ found << data.relative_path unless found.include?(data.relative_path)
+ result
+ end
+ end
+
+ def perform_recursion(path)
+ Puppet::FileServing::Metadata.search(self[:path], :links => self[:links], :recurse => self[:recurse], :ignore => self[:ignore])
+ end
+
# Recurse into the directory. This basically just calls 'localrecurse'
# and maybe 'sourcerecurse', returning the collection of generated
# files.
def recurse
- # are we at the end of the recursion?
- return unless self.recurse?
-
- recurse = self[:recurse]
- # we might have a string, rather than a number
- if recurse.is_a?(String)
- if recurse =~ /^[0-9]+$/
- recurse = Integer(recurse)
- else # anything else is infinite recursion
- recurse = true
- end
+ children = recurse_local
+
+ if self[:target]
+ children += recurse_link
end
- if recurse.is_a?(Integer)
- recurse -= 1
+ if self[:source]
+ recurse_remote
end
-
+
+ return children.collect { |child| newchild(child.relative_path) }.reject { |child| child.nil? }
+
children = []
# We want to do link-recursing before normal recursion so that all
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 5eefb1dcb..03cc311b4 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -66,8 +66,14 @@ module Puppet
uncheckable
validate do |source|
- unless @resource.uri2obj(source)
- raise Puppet::Error, "Invalid source %s" % source
+ begin
+ uri = URI.parse(URI.escape(source))
+ rescue => detail
+ self.fail "Could not understand source %s: %s" % [source, detail.to_s]
+ end
+
+ unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
+ self.fail "Cannot use URLs of type '%s' as source for fileserving" % [uri.scheme]
end
end