From d7c9c765dbf28df3631e709832c44c343569cb53 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 10 Aug 2011 16:20:00 -0700 Subject: (#8740) Do not enumerate files in the root directory. Previously the command 'puppet resource file' would enumerate all files in the root directory, and generate an exception if the file type was not a directory, file, or link. Worse, it would also do this when a file or directory was specified, e.g. 'puppet resource file /etc/hosts'. Ideally, the find method of the ral terminus should not need to call the type's instances class method, instead just creating an instance of the type with the specified name and parameters. However, some types, like package, depend on this behavior. The type walks all providers and all instances that they provide, checking to see if the provider provides an instance with that name, and also warning if another provider provides an instance with the same name. Also, ideally, puppet should not blow up when encountering an unsupported file type, e.g. Unix domain socket, but that would be too big of a change for 2.6.x. This commit changes 'puppet resource file' to return a message saying that the operation is not supported: Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc The change is bit of a hack, as ideally, the file type's instances method could raise an exception when called in a 'search' context, but return an empty array in a 'find' context. But that also would be too big of a change for 2.6.x. This commit also adds spec tests for the resource application and file type, as well as an acceptance test, which creates a Unix domain socket in the root directory, while running 'puppet resource file'. Paired-with: Nick Lewis Reviewed-by: Jacob Helwig --- lib/puppet/application/resource.rb | 3 +++ lib/puppet/type/file.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index f55caa58a..bc4faf5e4 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -81,6 +81,9 @@ class Puppet::Application::Resource < Puppet::Application [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ] end else + if type == "file" + raise "Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc" + end Puppet::Resource.search( key, {} ) end.map(&format).join("\n") diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 630ebe5de..e91929cf8 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -310,8 +310,8 @@ Puppet::Type.newtype(:file) do super(path.gsub(/\/+/, '/').sub(/\/$/, '')) end - def self.instances(base = '/') - return self.new(:name => base, :recurse => true, :recurselimit => 1, :audit => :all).recurse_local.values + def self.instances + return [] end @depthfirst = false -- cgit