diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-10-18 15:24:37 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2011-01-23 04:25:42 +1100 |
commit | 70630b903b747db0148cd972b64e5162b8f459cc (patch) | |
tree | 9471eab0dd4fedeca5947792010a92af1ade7837 | |
parent | 76d1c2aefb32cc3688e3f7c0a5c8bbf713a123ed (diff) | |
download | puppet-70630b903b747db0148cd972b64e5162b8f459cc.tar.gz puppet-70630b903b747db0148cd972b64e5162b8f459cc.tar.xz puppet-70630b903b747db0148cd972b64e5162b8f459cc.zip |
Fix #3165 Ralsh (bin/puppet resource) can't manage files
This is based on the patch submitted by Owen Smith.
File management was being blocked by two problems: an obsolete, broken
`instances` method for the file type,
and a bug in the way resource/ral handled slashes in resource names.
This patch makes two changes to Owen's version:
1) our unit tests caught an
unexpected ruby quirk:
"text/".split("/")
and
"text/".split("/", 2)
do not return the same values.
2) File.instances now reproduces the old behavior of listing files in
the root directory. This is now implemented in terms of the existing
file recursion feature.
-rw-r--r-- | lib/puppet/indirector/resource/ral.rb | 9 | ||||
-rw-r--r-- | lib/puppet/type/file.rb | 21 |
2 files changed, 9 insertions, 21 deletions
diff --git a/lib/puppet/indirector/resource/ral.rb b/lib/puppet/indirector/resource/ral.rb index 1c2ab14ae..bc41d14ae 100644 --- a/lib/puppet/indirector/resource/ral.rb +++ b/lib/puppet/indirector/resource/ral.rb @@ -34,12 +34,17 @@ class Puppet::Resource::Ral < Puppet::Indirector::Code private + # {type,resource}_name: the resource name may contain slashes: + # File["/etc/hosts"]. To handle, assume the type name does + # _not_ have any slashes in it, and split only on the first. + def type_name( request ) - request.key.split('/')[0] + request.key.split('/', 2)[0] end def resource_name( request ) - request.key.split('/')[1] + name = request.key.split('/', 2)[1] + name unless name == "" end def type( request ) diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index eee948cd5..dc0fe7b24 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -290,25 +290,8 @@ Puppet::Type.newtype(:file) do super(path.gsub(/\/+/, '/').sub(/\/$/, '')) end - # List files, but only one level deep. - def self.instances(base = "/") - return [] unless FileTest.directory?(base) - - files = [] - Dir.entries(base).reject { |e| - e == "." or e == ".." - }.each do |name| - path = File.join(base, name) - if obj = self[path] - obj[:audit] = :all - files << obj - else - files << self.new( - :name => path, :audit => :all - ) - end - end - files + def self.instances(base = '/') + return self.new(:name => base, :recurse => true, :recurselimit => 1, :audit => :all).recurse_local.values end @depthfirst = false |