summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-10-31 12:13:55 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-11-05 18:56:55 +1100
commitb8470b8064503baea21d43d5c1dcf349bc4daf59 (patch)
treeefea7a9ac5bd5d16665d1c8ac1b4b568dd95799a /lib
parent5b750c225ff0c646341282aa867d92dbe15509cd (diff)
downloadpuppet-b8470b8064503baea21d43d5c1dcf349bc4daf59.tar.gz
puppet-b8470b8064503baea21d43d5c1dcf349bc4daf59.tar.xz
puppet-b8470b8064503baea21d43d5c1dcf349bc4daf59.zip
Fix #2757 & CSR 92 (symlinks in recursively managed dirs)
The fundemental problem was that, despite what the comment said, the early bailout for file content management only applied to directories, not to links. Making links bail out at as well fixed the problem for most users. However, it would still occur for users with mixed ruby version system since there were no to_/from_pson methods for file metadata. So the second (and far larger) part of this patch adds metadata pson support. The testing is unit level only, as there's no pratical way to do the cross-ruby-version acceptance testing and no benifit to doing "integration" testing short of that. Signed-off-by: Markus Roberts <Markus@reductivelabs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/external/pson/common.rb2
-rw-r--r--lib/puppet/file_serving/base.rb15
-rw-r--r--lib/puppet/file_serving/metadata.rb45
-rwxr-xr-xlib/puppet/type/file/content.rb8
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