Re: Symlinks and ownership

From: Date: Thu, 23 Apr 2009 17:48:06 +0000
Subject: Re: Symlinks and ownership
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-291886@lists.php.net to get a copy of this message
On Thu, Apr 23, 2009 at 13:21, Christoph Boget <christoph.boget@gmail.com> 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@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

« previous php.general (#291886) next »