lib/puppet/network/handler/fileserver.rb in puppet-0.24.9 vs lib/puppet/network/handler/fileserver.rb in puppet-0.25.0
- old
+ new
@@ -51,11 +51,11 @@
@mounts = {}
Puppet.debug "No file server configuration file; autocreating #{MODULES} mount with default permissions"
mount = Mount.new(MODULES)
mount.allow("*")
@mounts[MODULES] = mount
-
+
Puppet.debug "No file server configuration file; autocreating #{PLUGINS} mount with default permissions"
mount = PluginMount.new(PLUGINS)
mount.allow("*")
@mounts[PLUGINS] = mount
end
@@ -75,11 +75,11 @@
metadata = Puppet::FileServing::Metadata.new(url, :path => full_path, :links => links)
return "" unless metadata.exist?
begin
- metadata.collect_attributes
+ metadata.collect
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err detail
return ""
end
@@ -143,11 +143,11 @@
return ""
end
desc.collect { |sub| sub.join("\t") }.join("\n")
end
-
+
def local?
self.local
end
# Is a given mount available?
@@ -252,13 +252,12 @@
else
env = nil
end
# And use the environment to look up the module.
- mod = Puppet::Module::find(module_name, env)
- if mod
- return @mounts[MODULES].copy(mod.name, mod.files)
+ if mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?
+ return @mounts[MODULES].copy(mod.name, mod.file_directory)
else
return nil
end
end
@@ -277,25 +276,25 @@
File.open(@configuration.file) { |f|
mount = nil
count = 1
f.each { |line|
case line
- when /^\s*#/: next # skip comments
- when /^\s*$/: next # skip blank lines
- when /\[([-\w]+)\]/:
+ when /^\s*#/; next # skip comments
+ when /^\s*$/; next # skip blank lines
+ when /\[([-\w]+)\]/
name = $1
if newmounts.include?(name)
raise FileServerError, "%s is already mounted at %s" %
[newmounts[name], name], count, @configuration.file
end
mount = Mount.new(name)
newmounts[name] = mount
- when /^\s*(\w+)\s+(.+)$/:
+ when /^\s*(\w+)\s+(.+)$/
var = $1
value = $2
case var
- when "path":
+ when "path"
if mount.name == MODULES
Puppet.warning "The '#{mount.name}' module can not have a path. Ignoring attempt to set it"
else
begin
mount.path = value
@@ -303,21 +302,21 @@
Puppet.err "Removing mount %s: %s" %
[mount.name, detail]
newmounts.delete(mount.name)
end
end
- when "allow":
+ when "allow"
value.split(/\s*,\s*/).each { |val|
begin
mount.info "allowing %s access" % val
mount.allow(val)
rescue AuthStoreError => detail
raise FileServerError.new(detail.to_s,
count, @configuration.file)
end
}
- when "deny":
+ when "deny"
value.split(/\s*,\s*/).each { |val|
begin
mount.info "denying %s access" % val
mount.deny(val)
rescue AuthStoreError => detail
@@ -348,18 +347,18 @@
Puppet.debug "No #{MODULES} mount given; autocreating with default permissions"
mount = Mount.new(MODULES)
mount.allow("*")
newmounts[MODULES] = mount
end
-
+
unless newmounts[PLUGINS]
Puppet.debug "No #{PLUGINS} mount given; autocreating with default permissions"
mount = PluginMount.new(PLUGINS)
mount.allow("*")
newmounts[PLUGINS] = mount
end
-
+
unless newmounts[PLUGINS].valid?
Puppet.debug "No path given for #{PLUGINS} mount; creating a special PluginMount"
# We end up here if the user has specified access rules for
# the plugins mount, without specifying a path (which means
# they want to have the default behaviour for the mount, but
@@ -371,11 +370,11 @@
mount.instance_variable_set(:@declarations,
newmounts[PLUGINS].instance_variable_get(:@declarations)
)
newmounts[PLUGINS] = mount
end
-
+
# Verify each of the mounts are valid.
# We let the check raise an error, so that it can raise an error
# pointing to the specific problem.
newmounts.each { |name, mount|
unless mount.valid?
@@ -432,11 +431,11 @@
Puppet::Util.logmethods(self, true)
# Create a map for a specific client.
def clientmap(client)
{
- "h" => client.sub(/\..*$/, ""),
+ "h" => client.sub(/\..*$/, ""),
"H" => client,
"d" => client.sub(/[^.]+\./, "") # domain name
}
end
@@ -453,11 +452,11 @@
# Else, use the local information
map = localmap()
end
path.gsub(/%(.)/) do |v|
key = $1
- if key == "%"
+ if key == "%"
"%"
else
map[key] || v
end
end
@@ -475,11 +474,14 @@
# Return a fully qualified path, given a short path and
# possibly a client name.
def file_path(relative_path, node = nil)
full_path = path(node)
- raise ArgumentError.new("Mounts without paths are not usable") unless full_path
+ unless full_path
+ p self
+ raise ArgumentError.new("Mounts without paths are not usable") unless full_path
+ end
# If there's no relative path name, then we're serving the mount itself.
return full_path unless relative_path and relative_path != "/"
return File.join(full_path, relative_path)
@@ -496,26 +498,29 @@
self.path = path
else
@path = nil
end
+ @files = {}
+
super()
end
def fileobj(path, links, client)
obj = nil
- if obj = Puppet.type(:file)[file_path(path, client)]
+ if obj = @files[file_path(path, client)]
# This can only happen in local fileserving, but it's an
# important one. It'd be nice if we didn't just set
# the check params every time, but I'm not sure it's worth
# the effort.
obj[:check] = CHECKPARAMS
else
- obj = Puppet.type(:file).create(
+ obj = Puppet::Type.type(:file).new(
:name => file_path(path, client),
:check => CHECKPARAMS
)
+ @files[file_path(path, client)] = obj
end
if links == :manage
links = :follow
end
@@ -528,11 +533,11 @@
return obj
end
# Read the contents of the file at the relative path given.
def read_file(relpath, client)
- File.read(file_path(relpath, client))
+ File.read(file_path(relpath, client))
end
# Cache this manufactured map, since if it's used it's likely
# to get used a lot.
def localmap
@@ -665,11 +670,15 @@
end
def reclist(abspath, recurse, ignore)
require 'puppet/file_serving'
require 'puppet/file_serving/fileset'
- args = { :recurse => recurse, :links => :follow }
+ if recurse.is_a?(Fixnum)
+ args = { :recurse => true, :recurselimit => recurse, :links => :follow }
+ else
+ args = { :recurse => recurse, :links => :follow }
+ end
args[:ignore] = ignore if ignore
fs = Puppet::FileServing::Fileset.new(abspath, args)
ary = fs.files.collect do |file|
if file == "."
file = "/"
@@ -687,43 +696,42 @@
end
# A special mount class specifically for the plugins mount -- just
# has some magic to effectively do a union mount of the 'plugins'
# directory of all modules.
- #
+ #
class PluginMount < Mount
def path(client)
''
end
def mod_path_exists?(mod, relpath, client = nil)
- File.exists?(File.join(mod, PLUGINS, relpath))
+ ! mod.plugin(relpath).nil?
end
def path_exists?(relpath, client = nil)
- !valid_modules.find { |m| mod_path_exists?(m, relpath, client) }.nil?
+ !valid_modules(client).find { |mod| mod.plugin(relpath) }.nil?
end
def valid?
true
end
def mod_file_path(mod, relpath, client = nil)
File.join(mod, PLUGINS, relpath)
end
-
+
def file_path(relpath, client = nil)
- return nil unless mod = valid_modules.map { |m| mod_path_exists?(m, relpath, client) ? m : nil }.compact.first
- mod_file_path(mod, relpath, client)
+ return nil unless mod = valid_modules(client).find { |m| m.plugin(relpath) }
+ mod.plugin(relpath)
end
# create a list of files by merging all modules
def list(relpath, recurse, ignore, client = nil)
result = []
- valid_modules.each do |m|
- modpath = mod_file_path(m, relpath, client)
- if FileTest.exists?(modpath)
+ valid_modules(client).each do |mod|
+ if modpath = mod.plugin(relpath)
if FileTest.directory?(modpath) and recurse
ary = reclist(modpath, recurse, ignore)
ary = [] if ary.nil?
result += ary
else
@@ -733,13 +741,13 @@
end
result
end
private
- def valid_modules
- Puppet::Module.all.find_all { |m| File.directory?(File.join(m, PLUGINS)) }
+ def valid_modules(client)
+ Puppet::Node::Environment.new.modules.find_all { |mod| mod.exist? }
end
-
+
def add_to_filetree(f, filetree)
first, rest = f.split(File::SEPARATOR, 2)
end
end
end