summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-24 14:11:48 -0500
committerLuke Kanies <luke@madstop.com>2008-08-26 22:40:40 -0700
commit550e3d6ad5aadfe99fc1e10efa77cc193d3a9df3 (patch)
tree5945db48003ab63c68db4f5d229345fb3ecef1a9 /lib/puppet
parent90e70227b0bb7cfd104ae34de8f7c2b7250edb09 (diff)
downloadpuppet-550e3d6ad5aadfe99fc1e10efa77cc193d3a9df3.tar.gz
puppet-550e3d6ad5aadfe99fc1e10efa77cc193d3a9df3.tar.xz
puppet-550e3d6ad5aadfe99fc1e10efa77cc193d3a9df3.zip
Finishing the rename of FileBase => Base.
Git did something really strange, in that it apparently didn't add the new base.rb files even though I used 'git mv'. Also fixing some other failing tests I hadn't previously tracked down because of the magical tuple of autotest's suckiness and my laziness. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/file_serving/base.rb76
-rw-r--r--lib/puppet/indirector/module_files.rb7
2 files changed, 79 insertions, 4 deletions
diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb
new file mode 100644
index 000000000..1cfd0bc4c
--- /dev/null
+++ b/lib/puppet/file_serving/base.rb
@@ -0,0 +1,76 @@
+#
+# 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::Base
+ 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/indirector/module_files.rb b/lib/puppet/indirector/module_files.rb
index cf5c29cab..40dd06941 100644
--- a/lib/puppet/indirector/module_files.rb
+++ b/lib/puppet/indirector/module_files.rb
@@ -21,7 +21,7 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
# Make sure our file path starts with /modules, so that we authorize
# against the 'modules' mount.
- path = uri.path =~ /^\/modules/ ? uri.path : "/modules" + uri.path
+ path = uri.path =~ /^modules\// ? uri.path : "modules/" + uri.path
configuration.authorized?(path, :node => request.node, :ipaddress => request.ip)
end
@@ -66,9 +66,8 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
def find_path(request)
uri = key2uri(request.key)
- # Strip off /modules if it's there -- that's how requests get routed to this terminus.
- # Also, strip off the leading slash if present.
- module_name, relative_path = uri.path.sub(/^\/modules\b/, '').sub(%r{^/}, '').split(File::Separator, 2)
+ # Strip off modules/ if it's there -- that's how requests get routed to this terminus.
+ module_name, relative_path = uri.path.sub(/^modules\//, '').sub(%r{^/}, '').split(File::Separator, 2)
# And use the environment to look up the module.
return nil unless mod = find_module(module_name, request.node)