summaryrefslogtreecommitdiffstats
path: root/lib/puppet/file_serving
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/file_serving')
-rw-r--r--lib/puppet/file_serving/content.rb10
-rw-r--r--lib/puppet/file_serving/file_base.rb33
-rw-r--r--lib/puppet/file_serving/indirection_hooks.rb (renamed from lib/puppet/file_serving/terminus_selector.rb)2
-rw-r--r--lib/puppet/file_serving/metadata.rb20
-rw-r--r--lib/puppet/file_serving/terminus_helper.rb8
5 files changed, 52 insertions, 21 deletions
diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb
index 3cb428e63..9398513e7 100644
--- a/lib/puppet/file_serving/content.rb
+++ b/lib/puppet/file_serving/content.rb
@@ -5,23 +5,23 @@
require 'puppet/indirector'
require 'puppet/file_serving'
require 'puppet/file_serving/file_base'
-require 'puppet/file_serving/terminus_selector'
+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
extend Puppet::Indirector
- indirects :file_content, :extend => Puppet::FileServing::TerminusSelector
+ indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks
attr_reader :path
# Read the content of our file in.
- def content(base = nil)
+ def content
# This stat can raise an exception, too.
- raise(ArgumentError, "Cannot read the contents of links unless following links") if stat(base).ftype == "symlink"
+ raise(ArgumentError, "Cannot read the contents of links unless following links") if stat().ftype == "symlink"
- ::File.read(full_path(base))
+ ::File.read(full_path())
end
# Just return the file contents as the yaml. This allows us to
diff --git a/lib/puppet/file_serving/file_base.rb b/lib/puppet/file_serving/file_base.rb
index b2e9a0656..7f169d1ea 100644
--- a/lib/puppet/file_serving/file_base.rb
+++ b/lib/puppet/file_serving/file_base.rb
@@ -7,18 +7,19 @@ 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 :path, :base_path
+ attr_accessor :key
- def full_path(base = nil)
- base ||= base_path || raise(ArgumentError, "You must set or provide a base path")
+ # 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
- full = File.join(base, self.path)
+ relative_path ? File.join(path, relative_path) : path
end
- def initialize(path, options = {})
+ def initialize(key, options = {})
raise ArgumentError.new("Files must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/
- @path = path
+ @key = key
@links = :manage
options.each do |param, value|
@@ -30,17 +31,33 @@ class Puppet::FileServing::FileBase
end
end
+ # Determine how we deal with links.
attr_reader :links
def links=(value)
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(base = nil)
+ def stat
unless defined?(@stat_method)
@stat_method = self.links == :manage ? :lstat : :stat
end
- File.send(@stat_method, full_path(base))
+ File.send(@stat_method, full_path())
end
end
diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/indirection_hooks.rb
index 06b53ddb1..141642efe 100644
--- a/lib/puppet/file_serving/terminus_selector.rb
+++ b/lib/puppet/file_serving/indirection_hooks.rb
@@ -8,7 +8,7 @@ require 'puppet/file_serving'
# This module is used to pick the appropriate terminus
# in file-serving indirections. This is necessary because
# the terminus varies based on the URI asked for.
-module Puppet::FileServing::TerminusSelector
+module Puppet::FileServing::IndirectionHooks
PROTOCOL_MAP = {"puppet" => :rest, "file" => :file, "puppetmounts" => :file_server}
# Pick an appropriate terminus based on the protocol.
diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb
index 62ebccca9..e26e75844 100644
--- a/lib/puppet/file_serving/metadata.rb
+++ b/lib/puppet/file_serving/metadata.rb
@@ -7,14 +7,24 @@ require 'puppet/indirector'
require 'puppet/file_serving'
require 'puppet/file_serving/file_base'
require 'puppet/util/checksums'
-require 'puppet/file_serving/terminus_selector'
+require 'puppet/file_serving/indirection_hooks'
# A class that handles retrieving file metadata.
class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase
+ module MetadataHelper
+ include Puppet::FileServing::IndirectionHooks
+
+ def post_find(instance)
+ end
+
+ def post_search(key, options = {})
+ end
+ end
+
include Puppet::Util::Checksums
extend Puppet::Indirector
- indirects :file_metadata, :extend => Puppet::FileServing::TerminusSelector
+ indirects :file_metadata, :extend => Puppet::FileServing::IndirectionHooks
attr_reader :path, :owner, :group, :mode, :checksum_type, :checksum, :ftype, :destination
@@ -27,9 +37,9 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase
# Retrieve the attributes for this file, relative to a base directory.
# Note that File.stat raises Errno::ENOENT if the file is absent and this
# method does not catch that exception.
- def collect_attributes(base = nil)
- real_path = full_path(base)
- stat = stat(base)
+ def collect_attributes
+ real_path = full_path()
+ stat = stat()
@owner = stat.uid
@group = stat.gid
@ftype = stat.ftype
diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb
index 9542cbf84..d465aa493 100644
--- a/lib/puppet/file_serving/terminus_helper.rb
+++ b/lib/puppet/file_serving/terminus_helper.rb
@@ -8,8 +8,12 @@ require 'puppet/file_serving/fileset'
# Define some common methods for FileServing termini.
module Puppet::FileServing::TerminusHelper
# Create model instances for all files in a fileset.
- def path2instances(path, options = {})
+ def path2instances(key, path, options = {})
args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = options[param] if options[param]; hash }
- Puppet::FileServing::Fileset.new(path, args).files.collect { |file| model.new(file) }
+ Puppet::FileServing::Fileset.new(path, args).files.collect do |file|
+ inst = model.new(File.join(key, file), :path => path, :relative_path => file)
+ inst.links = options[:links] if options[:links]
+ inst
+ end
end
end