The restriction of chown to the superuser is a property of the OS, not the 
files. The example from the pod is:

use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
my $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);

Thinking about it, perhaps that means that it's a method on $*OS.

The use of filetest operators as a way to specify the desired chmod modes
seems good, but I'm not sure how to specify the signature. I can imagine:

our multi chmod ( Int $mode, [EMAIL PROTECTED] );
our multi chmod ( PermissionModifier :$owner,
                          PermissionModifier :$group,
                          PermissionModifier :$other,
                     [EMAIL PROTECTED]);

but I'm not sure how to define that a PermissionModifer object can be created
as a chain of positive and negative options so that these would work:

    @exe_files ==> chmod :owner( :x ), :group( :x ), :other( :!x );
    @my_files  ==> chmod :owner( :r :w ), :group( :r :!w ), :other( :!r :!w );

There would be a little less line-noise if these could be passed as:

    @my_files ==> chmod :owner<r w> :group<r !w> :other<!r !w>;




________________________________
From: Moritz Lenz <[EMAIL PROTECTED]>
To: dpuu <[EMAIL PROTECTED]>
Cc: perl6-language@perl.org
Sent: Friday, November 21, 2008 10:30:08 AM
Subject: Re: S16: chown, chmod

dpuu wrote:
> Question: is it appropriate to P6 look&feel to have methods on
> functions?

I don't think that's such a good idea in this case. If a file is
chown'able is not a property of the chown function, but of the file.

> The definition of C<chown> includes the statement that it's not
> available on most system unless you're superuser; and this can be
> checked using a POSIX incantation. I was wondering if it would be
> reasonable to provide this as a method on the chown function, so that
> a user could say:
> 
>   if &chown.is_restricted {
>     ...
>   }
>   else {
>     chown $user, $group <== @files
>   }


I'd rather go with the "try it and fail() if you can't" approach, partly
because of race conditions, partly because it's much more reliable in
the presence of extended security models (think of SeLinux for example).

If 'use fatal' is in effect, that dies, if not, you can check the return
value.


For chmod() I could imagine an interface like this:

$file.chmod(:8<540>);
$file.chmod( :set, :user => :r & :x, :group => :r)
       # both same as 'chmod 540 $file'

$file.chmod( :modifiy, :other => :!x)
       # same as 'chmod o-x $file'

Cheers,
Moritz

-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/

Reply via email to