diff options
| author | lutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-26 06:29:59 +0000 |
|---|---|---|
| committer | lutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-26 06:29:59 +0000 |
| commit | 55d3fb8360bff73711f3d4bf9286fb380a1b2d61 (patch) | |
| tree | 353f82a430da1a59d39ca74bf8308bf6b6407b92 /lib | |
| parent | 2540cdf2704eb62dfa760c334fcde105645ee007 (diff) | |
| download | puppet-55d3fb8360bff73711f3d4bf9286fb380a1b2d61.tar.gz puppet-55d3fb8360bff73711f3d4bf9286fb380a1b2d61.tar.xz puppet-55d3fb8360bff73711f3d4bf9286fb380a1b2d61.zip | |
Support for %h and %H replacement in the path of fileserver modules.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1490 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/puppet/server/fileserver.rb | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb index 7e0e49105..983e39271 100755 --- a/lib/puppet/server/fileserver.rb +++ b/lib/puppet/server/fileserver.rb @@ -1,6 +1,7 @@ require 'puppet' require 'webrick/httpstatus' require 'cgi' +require 'delegate' module Puppet class FileServerError < Puppet::Error; end @@ -40,7 +41,7 @@ class Server raise Puppet::FileServerError, "Cannot currently copy links" end - mount, path = splitpath(file) + mount, path = splitpath(file, client) authcheck(file, mount, client, clientip) @@ -133,7 +134,7 @@ class Server # List a specific directory's contents. def list(dir, links = :ignore, recurse = false, ignore = false, client = nil, clientip = nil) readconfig - mount, path = splitpath(dir) + mount, path = splitpath(dir, client) authcheck(dir, mount, client, clientip) @@ -297,7 +298,7 @@ class Server def retrieve(file, links = :ignore, client = nil, clientip = nil) readconfig links = links.intern if links.is_a? String - mount, path = splitpath(file) + mount, path = splitpath(file, client) authcheck(file, mount, client, clientip) @@ -390,7 +391,7 @@ class Server end # Split the path into the separate mount point and path. - def splitpath(dir) + def splitpath(dir, client) # the dir is based on one of the mounts # so first retrieve the mount path mount = nil @@ -410,6 +411,7 @@ class Server # And now replace the name with the actual object. mount = @mounts[mount] + mount = SubstMount.new(mount, client) unless client.nil? else raise FileServerError, "Fileserver error: Invalid path '%s'" % dir end @@ -529,7 +531,13 @@ class Server # Set the path. def path=(path) unless FileTest.exists?(path) - raise FileServerError, "%s does not exist" % path + map = { "h" => "\000", "H" => "\000" } + # FIXME: What should we do if there are replacement + # patterns in path ? Replace with '*' and glob ? + # But that could turn out to be _very_ expensive + unless Mount::subst(path, map).index("\000") + raise FileServerError, "%s does not exist" % path + end end @path = path end @@ -553,6 +561,38 @@ class Server raise FileServerError, "No path specified" end end + + # Replace occurences of %C in PATH with entries from MAP and + # return a new string. Literal percent signs can be included as + # '%%', and a replacement is only done when C is a key in MAP + def self.subst(path, map) + path.gsub(/%./) do |v| + if v == "%%" + "%" + elsif ! map.key?(v[1,1]) + v + else + map[v[1,1]] + end + end + end + + end + + # A mount that does substitutions in the path on the fly + class SubstMount < DelegateClass(Mount) + def initialize(mount, client) + @mount = mount + super(@mount) + @map = { + "h" => client.sub(/\..*$/, ""), + "H" => client + } + end + + def path + Mount::subst(@mount.path, @map) + end end end end |
