On Mon, Oct 11, 2010 at 11:24 AM, Markus Roberts <[email protected]>wrote:
> So revisiting this patch because it caused #4963 and #4975 I noticed the
> change from the first version:
>
> + #Read in /etc/shadow, find the line for this user (skipping comments,
>> because who knows) and return it
>> #No abstraction, all esoteric knowledge of file formats, yay
>> + def shadow_entry
>> + return @shadow_entry if defined? @shadow_entry
>> + @shadow_entry = File.readlines("/etc/shadow").reject { |r| r =~
>> /^[^\w]/ }.collect { |l| l.chomp.split(':') }.find { |user, _| user ==
>> @resource[:name] }
>> + end
>> +
>> def password
>> - #got perl?
>> - if ary = File.readlines("/etc/shadow").reject { |r| r =~
>> /^[^\w]/}.collect { |l| l.split(':')[0..1] }.find { |user, passwd| user ==
>> @resource[:name] }
>> - pass = ary[1]
>> - end
>> - pass
>> + shadow_entry[1] if shadow_entry
>> end
>>
>
> I have several objections to this code, such as the awful, laborious
> "return ... if defined ..." recreation of "||=", but the most serious is the
> change in behaviour: how does caching the shadow entry for the first user we
> encounter in the provider play out when more than one user is being managed?
>
>
I believe every user resource has its own associated instance of the
provider, so this shouldn't cause a behavior change. However, I'm not
totally sure of that, and it was something I overlooked, not an assumption I
deliberately made. So that needs to be verified, at least. The "if defined?"
is probably a mistake and ought to be replaced with ||=. The intent was to
distinguish between not set and set to nil, when really, the result is the
same, although we would re-parse the shadow file on every call to
shadow_entry if the entry weren't present.
> -- Markus
> -----------------------------------------------------------
> The power of accurate observation is
> commonly called cynicism by those
> who have not got it. ~George Bernard Shaw
> ------------------------------------------------------------
>
> --
> 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]<puppet-dev%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>
--
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.