diff options
Diffstat (limited to 'lib/puppet/network/handler/fileserver.rb')
-rwxr-xr-x | lib/puppet/network/handler/fileserver.rb | 116 |
1 files changed, 22 insertions, 94 deletions
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 3ee4721f3..183979429 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -5,6 +5,9 @@ require 'cgi' require 'delegate' require 'sync' +require 'puppet/file_serving' +require 'puppet/file_serving/metadata' + class Puppet::Network::Handler AuthStoreError = Puppet::AuthStoreError class FileServerError < Puppet::Error; end @@ -59,40 +62,27 @@ class Puppet::Network::Handler # Describe a given file. This returns all of the manageable aspects # of that file. - def describe(url, links = :ignore, client = nil, clientip = nil) + def describe(url, links = :follow, client = nil, clientip = nil) links = links.intern if links.is_a? String - if links == :manage - raise Puppet::Network::Handler::FileServerError, "Cannot currently copy links" - end - mount, path = convert(url, client, clientip) - if client - mount.debug "Describing %s for %s" % [url, client] - end + mount.debug("Describing %s for %s" % [url, client]) if client - obj = nil - unless obj = mount.getfileobject(path, links, 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 metadata.exist? + + begin + metadata.collect_attributes + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err detail return "" end - currentvalues = mount.check(obj) - - desc = [] - CHECKPARAMS.each { |check| - if value = currentvalues[check] - desc << value - else - if check == "checksum" and currentvalues[:type] == "file" - mount.notice "File %s does not have data for %s" % - [obj.name, check] - end - desc << nil - end - } - - return desc.join("\t") + return metadata.attributes_with_tabs end # Create a new fileserving module. @@ -140,26 +130,18 @@ class Puppet::Network::Handler def list(url, links = :ignore, recurse = false, ignore = false, client = nil, clientip = nil) mount, path = convert(url, client, clientip) - if client - mount.debug "Listing %s for %s" % [url, client] - end + mount.debug "Listing %s for %s" % [url, client] if client - obj = nil - unless mount.path_exists?(path, client) - return "" - end + return "" unless mount.path_exists?(path, client) desc = mount.list(path, recurse, ignore, client) if desc.length == 0 - mount.notice "Got no information on //%s/%s" % - [mount, path] + mount.notice "Got no information on //%s/%s" % [mount, path] return "" end - - desc.collect { |sub| - sub.join("\t") - }.join("\n") + + desc.collect { |sub| sub.join("\t") }.join("\n") end def local? @@ -213,12 +195,7 @@ class Puppet::Network::Handler return "" end - str = nil - if links == :manage - raise Puppet::Error, "Cannot copy links yet." - else - str = mount.read_file(path, client) - end + str = mount.read_file(path, client) if @local return str @@ -452,55 +429,6 @@ class Puppet::Network::Handler Puppet::Util.logmethods(self, true) - def getfileobject(dir, links, client = nil) - unless path_exists?(dir, client) - self.debug "File source %s does not exist" % dir - return nil - end - - return fileobj(dir, links, client) - end - - # Run 'retrieve' on a file. This gets the actual parameters, so - # we can pass them to the client. - def check(obj) - # Retrieval is enough here, because we don't want to cache - # any information in the state file, and we don't want to generate - # any state changes or anything. We don't even need to sync - # the checksum, because we're always going to hit the disk - # directly. - - # We're now caching file data, using the LoadedFile to check the - # disk no more frequently than the :filetimeout. - path = obj[:path] - sync = sync(path) - unless data = @@files[path] - data = {} - sync.synchronize(Sync::EX) do - @@files[path] = data - data[:loaded_obj] = Puppet::Util::LoadedFile.new(path) - data[:values] = properties(obj) - return data[:values] - end - end - - changed = nil - sync.synchronize(Sync::SH) do - changed = data[:loaded_obj].changed? - end - - if changed - sync.synchronize(Sync::EX) do - data[:values] = properties(obj) - return data[:values] - end - else - sync.synchronize(Sync::SH) do - return data[:values] - end - end - end - # Create a map for a specific client. def clientmap(client) { |