summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/defaults.rb1
-rw-r--r--lib/puppet/module.rb4
-rw-r--r--lib/puppet/network/client/master.rb16
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb81
-rw-r--r--lib/puppet/util/settings.rb10
5 files changed, 57 insertions, 55 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 9a95c3cab..34f166108 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -111,6 +111,7 @@ module Puppet
guaranteed to work for those cases. In fact, the autoload
mechanism is responsible for making sure this directory
is in Ruby's search path",
+ :call_on_define => true, # Call our hook with the default value, so we always get the libdir set.
:hook => proc do |value|
if defined? @oldlibdir and $:.include?(@oldlibdir)
$:.delete(@oldlibdir)
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 3ff4fa470..54212710d 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -27,7 +27,9 @@ class Puppet::Module
return nil
end
- modpath = all(environment).find { |f| File::directory?(f) }
+ modpath = modulepath(environment).collect { |path|
+ File::join(path, modname)
+ }.find { |f| File::directory?(f) }
return nil unless modpath
return self.new(modname, modpath)
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index e0a51513c..0420a461f 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -370,7 +370,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
# Retrieve facts from the central server.
def self.getfacts
-
# Download the new facts
path = Puppet[:factpath].split(":")
files = []
@@ -436,21 +435,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
Puppet.warning "Could not load #{type} %s: %s" % [fqfile, detail]
end
end
- ensure
- # For some reason, the libdir doesn't end up in the load path
- # reliably, so we might need to add it here to make sure those shiny
- # new facts get picked up by My Friend Facter.
- $:.unshift(Puppet[:libdir]) unless $:.include?(Puppet[:libdir])
- # Reload everything.
- Facter.clear
- if Facter.respond_to? :loadfacts
- Facter.loadfacts
- elsif Facter.respond_to? :load
- Facter.load
- else
- raise Puppet::Error,
- "You must upgrade your version of Facter to use centralized facts"
- end
end
def self.loadfacts
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 1d8820402..52db3821f 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -45,7 +45,7 @@ class Puppet::Network::Handler
end
obj = nil
- unless obj = mount.getfileobject(path, links)
+ unless obj = mount.getfileobject(path, links, client)
return ""
end
@@ -116,11 +116,11 @@ class Puppet::Network::Handler
end
obj = nil
- unless mount.path_exists?(path)
+ unless mount.path_exists?(path, client)
return ""
end
- desc = mount.list(path, recurse, ignore)
+ desc = mount.list(path, recurse, ignore, client)
if desc.length == 0
mount.notice "Got no information on //%s/%s" %
@@ -167,7 +167,7 @@ class Puppet::Network::Handler
mount.info "Sending %s to %s" % [url, client]
end
- unless mount.path_exists?(path)
+ unless mount.path_exists?(path, client)
mount.debug "#{mount} reported that #{path} does not exist"
return ""
end
@@ -183,7 +183,7 @@ class Puppet::Network::Handler
if links == :manage
raise Puppet::Error, "Cannot copy links yet."
else
- str = mount.read_file(path)
+ str = mount.read_file(path, client)
end
if @local
@@ -420,13 +420,13 @@ class Puppet::Network::Handler
Puppet::Util.logmethods(self, true)
- def getfileobject(dir, links)
- unless path_exists?(dir)
+ 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)
+ return fileobj(dir, links, client)
end
# Run 'retrieve' on a file. This gets the actual parameters, so
@@ -510,6 +510,19 @@ class Puppet::Network::Handler
end
end
+ # 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
+
+ # 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)
+ end
+
# Create out object. It must have a name.
def initialize(name, path = nil)
unless name =~ %r{^[-\w]+$}
@@ -526,9 +539,9 @@ class Puppet::Network::Handler
super()
end
- def fileobj(path, links)
+ def fileobj(path, links, client)
obj = nil
- if obj = Puppet.type(:file)[real_path(path)]
+ if obj = Puppet.type(:file)[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
@@ -536,7 +549,7 @@ class Puppet::Network::Handler
obj[:check] = CHECKPARAMS
else
obj = Puppet.type(:file).create(
- :name => real_path(path),
+ :name => file_path(path, client),
:check => CHECKPARAMS
)
end
@@ -554,14 +567,8 @@ class Puppet::Network::Handler
end
# Read the contents of the file at the relative path given.
- def read_file(relpath)
- File.read(real_path(relpath))
- end
-
- # Determine the real path on disk for the given mount-relative
- # path
- def real_path(relpath)
- File.join(self.path(nil), relpath)
+ def read_file(relpath, client)
+ File.read(file_path(relpath, client))
end
# Cache this manufactured map, since if it's used it's likely
@@ -611,9 +618,9 @@ class Puppet::Network::Handler
# Verify that the path given exists within this mount's subtree.
#
- def path_exists?(relpath)
- File.exists?(File.join(path(nil), relpath))
- end
+ def path_exists?(relpath, client = nil)
+ File.exists?(file_path(relpath, client))
+ end
# Return the current values for the object.
def properties(obj)
@@ -683,8 +690,8 @@ class Puppet::Network::Handler
# a complete explanation would involve the words "crack pipe"
# and "bad batch".
#
- def list(relpath, recurse, ignore)
- reclist(File.join(path(nil), relpath), nil, recurse, ignore)
+ def list(relpath, recurse, ignore, client = nil)
+ reclist(file_path(relpath, client), nil, recurse, ignore)
end
# Recursively list the files in this tree.
@@ -737,19 +744,19 @@ class Puppet::Network::Handler
# directory of all modules.
#
class PluginMount < Mount
- def path(client)
- ''
+ def path(client)
+ ''
end
- def path_exists?(relpath)
- !valid_modules.find { |m| File.exists?(File.join(m, PLUGINS, relpath)) }.nil?
- end
-
- def valid?
- true
- end
+ def path_exists?(relpath, client = nil)
+ !valid_modules.find { |m| File.exists?(File.join(m, PLUGINS, relpath)) }.nil?
+ end
+
+ def valid?
+ true
+ end
- def real_path(relpath)
+ def file_path(relpath, client = nil)
mod = valid_modules.map { |m| File.exists?(File.join(m, PLUGINS, relpath)) ? m : nil }.compact.first
File.join(mod, PLUGINS, relpath)
end
@@ -761,7 +768,7 @@ class Puppet::Network::Handler
desc = [relpath]
- ftype = File.stat(real_path(abspath)).ftype
+ ftype = File.stat(file_path(abspath)).ftype
desc << ftype
if recurse.is_a?(Integer)
@@ -798,11 +805,11 @@ class Puppet::Network::Handler
private
def valid_modules
- Puppet::Module.all.find_all { |m| File.directory?(File.join(m, PLUGINS)) }
+ Puppet::Module.all.find_all { |m| File.directory?(File.join(m, PLUGINS)) }
end
def add_to_filetree(f, filetree)
- first, rest = f.split(File::SEPARATOR, 2)
+ first, rest = f.split(File::SEPARATOR, 2)
end
end
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 1db396dc4..957a6e7b9 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -516,6 +516,7 @@ class Puppet::Util::Settings
# pointless, but they help break things up a bit, anyway.
def setdefaults(section, defs)
section = symbolize(section)
+ call = []
defs.each { |name, hash|
if hash.is_a? Array
unless hash.length == 2
@@ -540,7 +541,14 @@ class Puppet::Util::Settings
@shortnames[short] = tryconfig
end
@config[name] = tryconfig
+
+ # Collect the settings that need to have their hooks called immediately.
+ # We have to collect them so that we can be sure we're fully initialized before
+ # the hook is called.
+ call << tryconfig if tryconfig.call_on_define
}
+
+ call.each { |setting| setting.handle(self.value(setting.name)) }
end
# Create a timer to check whether the file should be reparsed.
@@ -959,7 +967,7 @@ Generated on #{Time.now}.
# The base element type.
class CElement
- attr_accessor :name, :section, :default, :parent, :setbycli
+ attr_accessor :name, :section, :default, :parent, :setbycli, :call_on_define
attr_reader :desc, :short
# Unset any set value.