From a30ecf2aeffd71960bd806fb28cd6d1b8adc2452 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Tue, 23 Sep 2008 15:21:29 +0100 Subject: Make fileserver use fileset for recursion and handle dangling links by ignoring them fixing #1544 --- lib/puppet/network/handler/fileserver.rb | 65 ++++++++++++-------------------- 1 file changed, 24 insertions(+), 41 deletions(-) (limited to 'lib/puppet/network/handler') diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 3e62cdbd9..ff9b96f6c 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -651,55 +651,38 @@ class Puppet::Network::Handler # and "bad batch". # def list(relpath, recurse, ignore, client = nil) - reclist(file_path(relpath, client), nil, recurse, ignore) - end - - # Recursively list the files in this tree. - def reclist(basepath, abspath, recurse, ignore) - abspath = basepath if abspath.nil? - relpath = abspath.sub(%r{^#{basepath}}, '') - relpath = "/#{relpath}" if relpath[0] != ?/ #/ - - return unless FileTest.exists?(abspath) - - desc = [relpath] - - ftype = File.stat(abspath).ftype - - desc << ftype - if recurse.is_a?(Integer) - recurse -= 1 + require 'puppet/file_serving' + require 'puppet/file_serving/fileset' + abspath = file_path(relpath, client) + if FileTest.exists?(abspath) + if FileTest.directory?(abspath) and recurse + return reclist(abspath, recurse, ignore) + else + return [["/", File.stat(abspath).ftype]] + end end + return nil + end - ary = [desc] - if recurse == true or (recurse.is_a?(Integer) and recurse > -1) - if ftype == "directory" - children = Dir.entries(abspath) - if ignore - children = handleignore(children, abspath, ignore) - end - children.each { |child| - next if child =~ /^\.\.?$/ - reclist(basepath, File.join(abspath, child), recurse, ignore).each { |cobj| - ary << cobj - } - } + def reclist(abspath, recurse, ignore) + args = { :recurse => recurse, :links => :follow } + args[:ignore] = ignore if ignore + fs = Puppet::FileServing::Fileset.new(abspath, args) + ary = fs.files.collect do |file| + if file == "." + file = "/" + else + file = File.join("/", file ) end + stat = fs.stat(File.join(abspath, file)) + next if stat.nil? + [ file, stat.ftype ] end return ary.compact end - # Deal with ignore parameters. - def handleignore(files, path, ignore_patterns) - ignore_patterns.each do |ignore| - files.delete_if do |entry| - File.fnmatch(ignore, entry, File::FNM_DOTMATCH) - end - end - return files - end - end + end # A special mount class specifically for the plugins mount -- just # has some magic to effectively do a union mount of the 'plugins' -- cgit From 6bcfd9f021be13bfd3269eaa72bc289eab37a64f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 3 Oct 2008 13:11:44 -0500 Subject: Fixing #947 - pluginsync no longer fails poorly when no plugins exist Note that it still fails -- it's just a more reasonable failure. Signed-off-by: Luke Kanies --- lib/puppet/network/handler/fileserver.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/puppet/network/handler') diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index ff9b96f6c..da0a2befe 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -70,7 +70,9 @@ class Puppet::Network::Handler mount.debug("Describing %s for %s" % [url, client]) if client # use the mount to resolve the path for us. - metadata = Puppet::FileServing::Metadata.new(url, :path => mount.file_path(path, client), :links => links) + return "" unless full_path = mount.file_path(path, client) + + metadata = Puppet::FileServing::Metadata.new(url, :path => full_path, :links => links) return "" unless metadata.exist? @@ -710,7 +712,7 @@ class Puppet::Network::Handler end def file_path(relpath, client = nil) - mod = valid_modules.map { |m| mod_path_exists?(m, relpath, client) ? m : nil }.compact.first + return nil unless mod = valid_modules.map { |m| mod_path_exists?(m, relpath, client) ? m : nil }.compact.first mod_file_path(mod, relpath, client) end -- cgit From 28534471ef91301cc6a270f826dfff0f6021f89e Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sun, 5 Oct 2008 17:11:38 +0200 Subject: Fix several small regressions in plugins mount Since a30ecf2aeffd71960bd806fb28cd6d1b8adc2452, reclist has one parameter less, but Puppet::Network::Handler::PluginMount.list wasn't ported to the new API. While mounting plugins, reclist wasn't requiring 'file_serving/fileset', leading to an NameError. The change to the new API meant that we lost the existance test of plugins mount directory. It was failing when the client was mounting module plugins that weren't existing (like facter and no custom facts defined). Signed-off-by: Brice Figureau --- lib/puppet/network/handler/fileserver.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/puppet/network/handler') diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index da0a2befe..d87eb83fa 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -653,8 +653,6 @@ class Puppet::Network::Handler # and "bad batch". # def list(relpath, recurse, ignore, client = nil) - require 'puppet/file_serving' - require 'puppet/file_serving/fileset' abspath = file_path(relpath, client) if FileTest.exists?(abspath) if FileTest.directory?(abspath) and recurse @@ -667,6 +665,8 @@ class Puppet::Network::Handler end def reclist(abspath, recurse, ignore) + require 'puppet/file_serving' + require 'puppet/file_serving/fileset' args = { :recurse => recurse, :links => :follow } args[:ignore] = ignore if ignore fs = Puppet::FileServing::Fileset.new(abspath, args) @@ -720,9 +720,12 @@ class Puppet::Network::Handler def list(relpath, recurse, ignore, client = nil) result = [] valid_modules.each do |m| - ary = reclist(mod_file_path(m, relpath, client), nil, recurse, ignore) - ary = [] if ary.nil? - result += ary + modpath = mod_file_path(m, relpath, client) + if FileTest.exists?(modpath) + ary = reclist(modpath, recurse, ignore) + ary = [] if ary.nil? + result += ary + end end result end -- cgit From 4265825096677f596a6b8a2274e0bb802a60904c Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Wed, 8 Oct 2008 14:37:44 +0200 Subject: Fix #1636 - part2 - correct some client errors. #1636 original patch was incomplete, and on some cases, the client could report: "Failed to generate additional resources during transaction: None of the provided sources exist" The server was trying to recurse when asking to list files and thus was returning an empty response instead of a "file" response. --- lib/puppet/network/handler/fileserver.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/puppet/network/handler') diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index d87eb83fa..815d0ba82 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -722,9 +722,13 @@ class Puppet::Network::Handler valid_modules.each do |m| modpath = mod_file_path(m, relpath, client) if FileTest.exists?(modpath) - ary = reclist(modpath, recurse, ignore) - ary = [] if ary.nil? - result += ary + if FileTest.directory?(modpath) and recurse + ary = reclist(modpath, recurse, ignore) + ary = [] if ary.nil? + result += ary + else + result += [["/", File.stat(modpath).ftype]] + end end end result -- cgit From 53b7d42bb061ff1cfea3519179779a1cba2cf877 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 8 Oct 2008 22:03:22 -0500 Subject: Fixing the broken tests resulting from the fix for #1551. The test was expecting the current time, albeit as an integer. Signed-off-by: Luke Kanies --- lib/puppet/network/handler/master.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/network/handler') diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 05ae7b9a2..71b633a09 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -24,7 +24,7 @@ class Puppet::Network::Handler # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) # Always force a recompile. Newer clients shouldn't do this (as of April 2008). - return 0 + return Time.now.to_i end def initialize(hash = {}) -- cgit