diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/external/pson/common.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/file_serving/base.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/file_serving/metadata.rb | 45 | ||||
| -rwxr-xr-x | lib/puppet/type/file/content.rb | 8 |
4 files changed, 62 insertions, 8 deletions
diff --git a/lib/puppet/external/pson/common.rb b/lib/puppet/external/pson/common.rb index 71b85ce54..87bce988b 100644 --- a/lib/puppet/external/pson/common.rb +++ b/lib/puppet/external/pson/common.rb @@ -48,7 +48,7 @@ module PSON case when c.empty? then p when p.const_defined?(c) then p.const_get(c) - else raise ArgumentError, "can't find const #{path}" + else raise ArgumentError, "can't find const for unregistered document type #{path}" end end end diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb index c82bb1992..02132e885 100644 --- a/lib/puppet/file_serving/base.rb +++ b/lib/puppet/file_serving/base.rb @@ -74,4 +74,19 @@ class Puppet::FileServing::Base end File.send(@stat_method, full_path()) end + + def to_pson_data_hash + { + # No 'document_type' since we don't send these bare + 'data' => { + 'path' => @path, + 'relative_path' => @relative_path, + 'links' => @links + }, + 'metadata' => { + 'api_version' => 1 + } + } + end + end diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index 335dad497..275a090eb 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -71,8 +71,47 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base end end - def initialize(*args) - @checksum_type = "md5" - super + def initialize(path,data={}) + @owner = data.delete('owner') + @group = data.delete('group') + @mode = data.delete('mode') + if checksum = data.delete('checksum') + @checksum_type = checksum['type'] + @checksum = checksum['value'] + end + @checksum_type ||= "md5" + @ftype = data.delete('type') + @destination = data.delete('destination') + super(path,data) + end + + PSON.register_document_type('FileMetadata',self) + def to_pson_data_hash + { + 'document_type' => 'FileMetadata', + 'data' => super['data'].update({ + 'owner' => owner, + 'group' => group, + 'mode' => mode, + 'checksum' => { + 'type' => checksum_type, + 'value' => checksum + }, + 'type' => ftype, + 'destination' => destination, + }), + 'metadata' => { + 'api_version' => 1 + } + } + end + + def to_pson(*args) + to_pson_data_hash.to_pson(*args) + end + + def self.from_pson(data) + new(data.delete('path'), data) end + end diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index ff71a55ce..7f1908394 100755 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -114,14 +114,14 @@ module Puppet def retrieve return :absent unless stat = @resource.stat - + ftype = stat.ftype # Don't even try to manage the content on directories or links - return nil if stat.ftype == "directory" + return nil if ["directory","link"].include? ftype begin - return "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s + "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s rescue => detail - raise Puppet::Error, "Could not read %s: %s" % [@resource.title, detail] + raise Puppet::Error, "Could not read #{ftype} #{@resource.title}: #{detail}" end end |
