Re: Symlinks and ownership

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 23, 2009 at 13:21, Christoph Boget
<christoph.boget@xxxxxxxxx> wrote:
> Is there a reason why you can't programatically set ownership of a
> symbolic ink?  The following code

    You can't do it from the command line either, Chris.  This is
because chown and chgrp automatically dereference symlinks, so it's
actually changing ownership of the target.

> yet when I go take a look at it in the directory, the group for the
> link has not been changed to what I set it to.  Is that not something
> you can do for symbolic links programatically?

    To modify ownership of a symlink, you should instead use something
in the exec() family (exec(), passthru(), system(), etc.) and run the
command as if from the command line, with the option explicitly set
*not* to dereference symbolic links (which is -h or --no-dereference):

<?php

$symLink = 'linked'; // The actual name of the symbolic link file reference
$linkName = escapeshellarg($symLink); // Since we may accept user input

$ret = null; // This will only be populated and displayed once, on error.
$err = null; // We'll use this to define our errors.

exec('chgrp -h groupName '.$linkName,$ret,$err); // Group, using short flag
if(!is_null($err)) {
    die(print_r($ret));
}

exec('chown --no-dereference ownerName '.$linkName,$ret,$err); //
Owner, full flag
if(!is_null($err)) {
    die(print_r($ret));
}
?>

-- 
</Daniel P. Brown>
daniel.brown@xxxxxxxxxxxx || danbrown@xxxxxxx
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux