diff options
Diffstat (limited to 'lib/puppet/network/handler/fileserver.rb')
-rwxr-xr-x | lib/puppet/network/handler/fileserver.rb | 84 |
1 files changed, 38 insertions, 46 deletions
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 14319ef96..160dab1bb 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? @@ -654,55 +656,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 + 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) + 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) + 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' @@ -730,7 +715,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 @@ -738,9 +723,16 @@ 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) + 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 end |