> Um, gack.  You could do it with replication instead of shifts with
>>> something like:
>>>
>>>     rights = ((old_mode & 0777 & who_masks[what_letter]) * 0111111) >> 9
>>>     value = rights & 0777 & who_masks[who_letter]
>>>
>>>
>>
> (oops, hit send by mistake)
> Gack! That seems overly clever.
>

:) Yeah, but so did yours (I don't really like either of them).  Mine was
basically the old unix trick of using multiplication to spread the what over
the who.


> Maybe something like:
> rights = (old_mode & 0777)  / digits[what_letter]
> value = rights * digits[who_letter]
> (where digits maps [ugo] to 0100, 010, 01)
>

That's pretty much still the shift trick (which I think I like better than
the digits version).

I think the core problem is that all of the concerns have gotten merged (old
value propagation from [oug] on the right and don't care bits as
"unchanged").  Suppose we had a function and distribution over the who:

   def basic_rights_mask(letters,old_mask = 0)
     value = {   'r' => 4, 'w' => 2, 'x' => 1, 'u' => (old_mask >> 6) & 7,
'g' => (old_mask >> 3) & 7, 'o' => old_mask & 7 }
     letters.split(//).
       map { |ch| value[ch] || 0 }.
       inject(0) { |mask,bits| mask | bits }
   end

...and then an analog for s & t (I'm pretending X doesn't exist), we could
compute the "what" independent of the "who" (instead of having the nested
loops) and combine them with something like:

   basic_who = { 'u' => 0100, 'g' => 0010, 'o' => 0001, 'a' => 0111 }

   value = (basic_who[x] * basic_rights_mask(what,old_rights)) |
(extra_who[x] * extra_rights_mask(what,old_mask))

I don't know.  Those are my thoughts, for what they are worth.

-- M
-----------------------------------------------------------
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 puppet-...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to