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/file_base.rb18
-rw-r--r--lib/puppet/file_serving/metadata.rb40
2 files changed, 44 insertions, 14 deletions
diff --git a/lib/puppet/file_serving/file_base.rb b/lib/puppet/file_serving/file_base.rb
index 7f169d1ea..06b3ad9ef 100644
--- a/lib/puppet/file_serving/file_base.rb
+++ b/lib/puppet/file_serving/file_base.rb
@@ -9,16 +9,28 @@ require 'puppet/file_serving'
class Puppet::FileServing::FileBase
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
- relative_path ? File.join(path, relative_path) : path
+ if relative_path.nil? or relative_path == ""
+ path
+ else
+ File.join(path, relative_path)
+ end
end
def initialize(key, options = {})
- raise ArgumentError.new("Files must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/
-
@key = key
@links = :manage
diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb
index e26e75844..56712122c 100644
--- a/lib/puppet/file_serving/metadata.rb
+++ b/lib/puppet/file_serving/metadata.rb
@@ -28,6 +28,25 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase
attr_reader :path, :owner, :group, :mode, :checksum_type, :checksum, :ftype, :destination
+ PARAM_ORDER = [:mode, :ftype, :owner, :group]
+
+ def attributes_with_tabs
+ desc = []
+ PARAM_ORDER.each { |check|
+ check = :ftype if check == :type
+ desc << send(check)
+ }
+
+ case ftype
+ when "file", "directory": desc << checksum
+ when "link": desc << @destination
+ else
+ raise ArgumentError, "Cannot manage files of type %s" % ftype
+ end
+
+ return desc.join("\t")
+ end
+
def checksum_type=(type)
raise(ArgumentError, "Unsupported checksum type %s" % type) unless respond_to?("%s_file" % type)
@@ -45,13 +64,19 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase
@ftype = stat.ftype
- # Set the octal mode, but as a string.
- @mode = "%o" % (stat.mode & 007777)
+ # We have to mask the mode, yay.
+ @mode = stat.mode & 007777
- if stat.ftype == "symlink"
+ case stat.ftype
+ when "file":
+ @checksum = ("{%s}" % @checksum_type) + send("%s_file" % @checksum_type, real_path)
+ when "directory": # Always just timestamp the directory.
+ sumtype = @checksum_type.to_s =~ /time/ ? @checksum_type : "ctime"
+ @checksum = ("{%s}" % sumtype) + send("%s_file" % sumtype, path).to_s
+ when "link":
@destination = File.readlink(real_path)
else
- @checksum = get_checksum(real_path)
+ raise ArgumentError, "Cannot manage files of type %s" % stat.ftype
end
end
@@ -59,11 +84,4 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase
@checksum_type = "md5"
super
end
-
- private
-
- # Retrieve our checksum.
- def get_checksum(path)
- ("{%s}" % @checksum_type) + send("%s_file" % @checksum_type, path)
- end
end