diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/file_serving/content.rb | 17 | ||||
-rw-r--r-- | lib/puppet/file_serving/file_base.rb | 76 | ||||
-rw-r--r-- | lib/puppet/file_serving/metadata.rb | 4 |
3 files changed, 14 insertions, 83 deletions
diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb index 1114829f1..64f000eaa 100644 --- a/lib/puppet/file_serving/content.rb +++ b/lib/puppet/file_serving/content.rb @@ -4,23 +4,30 @@ require 'puppet/indirector' require 'puppet/file_serving' -require 'puppet/file_serving/file_base' +require 'puppet/file_serving/base' require 'puppet/file_serving/indirection_hooks' # A class that handles retrieving file contents. # It only reads the file when its content is specifically # asked for. -class Puppet::FileServing::Content < Puppet::FileServing::FileBase +class Puppet::FileServing::Content < Puppet::FileServing::Base extend Puppet::Indirector indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks attr_reader :path + def collect + end + # Read the content of our file in. def content - # This stat can raise an exception, too. - raise(ArgumentError, "Cannot read the contents of links unless following links") if stat().ftype == "symlink" + unless defined?(@content) and @content + # This stat can raise an exception, too. + raise(ArgumentError, "Cannot read the contents of links unless following links") if stat().ftype == "symlink" - ::File.read(full_path()) + p full_path + @content = ::File.read(full_path()) + end + @content end end diff --git a/lib/puppet/file_serving/file_base.rb b/lib/puppet/file_serving/file_base.rb deleted file mode 100644 index e87d683aa..000000000 --- a/lib/puppet/file_serving/file_base.rb +++ /dev/null @@ -1,76 +0,0 @@ -# -# Created by Luke Kanies on 2007-10-22. -# Copyright (c) 2007. All rights reserved. - -require 'puppet/file_serving' - -# The base class for Content and Metadata; provides common -# functionality like the behaviour around links. -class Puppet::FileServing::FileBase - attr_accessor :key - - # Does our file exist? - def exist? - begin - stat - return true - rescue => detail - return false - end - end - - # Return the full path to our file. Fails if there's no path set. - def full_path - raise(ArgumentError, "You must set a path to get a file's path") unless self.path - - if relative_path.nil? or relative_path == "" - path - else - File.join(path, relative_path) - end - end - - def initialize(key, options = {}) - @key = key - @links = :manage - - options.each do |param, value| - begin - send param.to_s + "=", value - rescue NoMethodError - raise ArgumentError, "Invalid option %s for %s" % [param, self.class] - end - end - end - - # Determine how we deal with links. - attr_reader :links - def links=(value) - value = :manage if value == :ignore - raise(ArgumentError, ":links can only be set to :manage or :follow") unless [:manage, :follow].include?(value) - @links = value - end - - # Set our base path. - attr_reader :path - def path=(path) - raise ArgumentError.new("Paths must be fully qualified") unless path =~ /^#{::File::SEPARATOR}/ - @path = path - end - - # Set a relative path; this is used for recursion, and sets - # the file's path relative to the initial recursion point. - attr_reader :relative_path - def relative_path=(path) - raise ArgumentError.new("Relative paths must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/ - @relative_path = path - end - - # Stat our file, using the appropriate link-sensitive method. - def stat - unless defined?(@stat_method) - @stat_method = self.links == :manage ? :lstat : :stat - end - File.send(@stat_method, full_path()) - end -end diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index beecaef48..a1265dd8b 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -5,12 +5,12 @@ require 'puppet' require 'puppet/indirector' require 'puppet/file_serving' -require 'puppet/file_serving/file_base' +require 'puppet/file_serving/base' require 'puppet/util/checksums' require 'puppet/file_serving/indirection_hooks' # A class that handles retrieving file metadata. -class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase +class Puppet::FileServing::Metadata < Puppet::FileServing::Base include Puppet::Util::Checksums |