On Feb 18, 2011, at 2:16 PM, Ian Ward Comfort wrote:

> On 18 Feb 2011, at 2:08 PM, Luke Kanies wrote:
>> On Feb 18, 2011, at 1:20 PM, Ian Ward Comfort wrote:
>>> On 18 Feb 2011, at 12:29 PM, Luke Kanies wrote:
>>>> It's actually pretty straightforward to do the trimming, I think - we 
>>>> currently just return the parent class, but we should instead search 
>>>> through possible parent dirs and see which ones are in the catalog.  
>>>> Something like:
>>>> 
>>>> autorequire(:file) do
>>>> dirs = 
>>>> File.dirname(self[:path]).split(File::SEPARATOR)[1..-1].inject([""]) { 
>>>> |list, d| list << File.join(list[-1], d); list }[1..-1].reverse
>>>> parent = dirs.find { |dir| catalog.resource(:file, dir) }
>>>> parent # either nil or a filename; works the same either way
>>>> end
>>> 
>>> Ah, hmm. Is that legit? Type.autorequire takes rel_catalog, which appears 
>>> to be the relative catalog against which autorequires are to be generated, 
>>> while this always uses the resource's catalog. But maybe rel_catalog is 
>>> only supposed to be for picking the final resources... or, actually, it 
>>> never seems to be used anyway.
>>> 
>>> OK, I'll give this approach a shot.
>> 
>> Are we looking at the same code?  I'm comparing to the existing autorequire 
>> in File:
>> 
>> autorequire(:file) do
>>   basedir = File.dirname(self[:path])
>>   if basedir != self[:path]
>>     basedir
>>   else  
>>     nil
>>   end   
>> end
> 
> I was looking at lib/puppet/type.rb:
> 
>  # Figure out of there are any objects we can automatically add as
>  # dependencies.
>  def autorequire(rel_catalog = nil)
>    rel_catalog ||= catalog
>    raise(Puppet::DevError, "You cannot add relationships without a catalog") 
> unless rel_catalog
>    ...
> 
> But I don't think anything ever supplies a rel_catalog. (Should it be 
> removed?) Anyway, your approach does work. I rewrote a little, hoping that 
> this would be more robust across POSIX and non-POSIX:
> 
>  autorequire(:file) do
>    basedir = File.dirname(self[:path])
>    if basedir != self[:path]
>      parents = []
>      until basedir == parents.last
>        parents.push basedir
>       basedir = File.dirname(basedir)
>      end
>      # The filename of the first parent found, or nil
>      parents.find { |dir| catalog.resource(:file, dir) }
>    else
>      nil
>    end
>  end
> 
> Now I'm just struggling to get rspec up and running on my RHEL box so I can 
> add some tests. (Is there any dev documentation I'm missing on this topic?)

autorequire is a bit of a weird beast, so I know why you're having problems.

My code was just about changing the behavior of existing autorequire, rather 
than adding a new kind of autorequire.

The code I sent was just replacing the *call* to that method you're looking at 
- weird, but true.

Glad to hear it seems to work.  And I notice that your code is far simpler and 
clearer than mine. :)


-- 
Humphrey's Law of the Efficacy of Prayer:
   In a dangerous world there will always be more people around whose
   prayers for their own safety have been answered than those whose
   prayers have not.
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199




-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to