On Feb 18, 2011, at 11:37 AM, Ian Ward Comfort wrote:

> On 18 Feb 2011, at 11:19 AM, Daniel Pittman wrote:
>> On Fri, Feb 18, 2011 at 10:48, Ian Ward Comfort <[email protected]> 
>> wrote:
>>> Yeah, requiring just the first managed parent, as suggested, would be 
>>> sufficient. I wasn't sure how to implement this, though, from a quick 
>>> glance through the code. The logic that iterates over possible autorequires 
>>> and adds relationships for anything found in the catalog is up in 
>>> Puppet.Type.
>>> 
>>> Any ideas for how to do that trimming?
>> 
>> Nope. :)
>> 
>> I was interested in characterizing the problem fully, so we understand what 
>> the request was, but I have no idea what the solution is presently.  That 
>> part is just code, though, so how hard can it be? ;)
> 
> Heh, right. I was trying to think of a clean way to give types a way to say, 
> "autorequire the first of these dependencies that's found in the catalog, and 
> ignore the rest". Adding an autorequirefirst method would do it in a 
> backwards-compatible way, but that feels icky.

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

-- 
Someday I want to be rich. Some people get so rich they lose all
respect for humanity. That's how rich I want to be.  --Rita Rudner
---------------------------------------------------------------------
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