chown -h 
Author Message
 chown -h

   is there some way to have the chown function in perl work like the
chown program itself does when invoked with the -h flag (i.e. affect a
symlink if that is its target, rather than the file to which that symlink
points)?  alternately, can chown be given device and inode info (as
obtained from lstat) to define its target, to get around the problem
entirely?

   tia,
   sweth.

--
Sweth Chandramouli
IS Coordinator, The George Washington University

<a href=" http://www.*-*-*.com/ ~sweth/disc.html">*</a>



Thu, 25 Jan 2001 03:00:00 GMT  
 chown -h

Quote:

> is there some way to have the chown function in perl work like the chown
> program itself does when invoked with the -h flag (i.e. affect a symlink
> if that is its target, rather than the file to which that symlink
> points)?  alternately, can chown be given device and inode info (as
> obtained from lstat) to define its target, to get around the problem
> entirely?

I'm afraid the answer is currently no to both questions.  Perl really
should get lchown() at some point, but it requires a lot of
platform-specific tweaking and detecting to figure out how to get it.  In
the meantime, you pretty much have to use system() to call chown -h.

--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker





Fri, 26 Jan 2001 03:00:00 GMT  
 chown -h

Quote:

>   is there some way to have the chown function in perl work like the
>chown program itself does when invoked with the -h flag (i.e. affect a
>symlink if that is its target, rather than the file to which that symlink
>points)?  

Use syscall(&SYS_lchown, ...).  See the `perlfunc' man page for more details.

Quote:
>alternately, can chown be given device and inode info (as obtained
>from lstat) to define its target, to get around the problem entirely?

Of course not.  If the operating system let you do that, it would
render  the filesystem's permissions void.


Fri, 26 Jan 2001 03:00:00 GMT  
 chown -h

Quote:


>> is there some way to have the chown function in perl work like the chown
>> program itself does when invoked with the -h flag (i.e. affect a symlink
>> if that is its target, rather than the file to which that symlink
>> points)?  alternately, can chown be given device and inode info (as
>> obtained from lstat) to define its target, to get around the problem
>> entirely?

>I'm afraid the answer is currently no to both questions.  Perl really
>should get lchown() at some point, but it requires a lot of
>platform-specific tweaking and detecting to figure out how to get it.  In
>the meantime, you pretty much have to use system() to call chown -h.

   in which case, which would be more efficient for a script that chowns a
large number of files, only a few of which are symlinks--using a system
call to the chown (with -h) program for each file, or doing a test before
each chown to see if it is a symlink and the system call is needed, like
this:



   if (($stats[0] != $lstats[0]) or ($stats[1] != $lstats[1])) {
      chown $newid, -1, $file
   } else {
      system ("/usr/local/bin/chown", "-h", "$file)
   };

Quote:
};

   on a related topic: since the chown function can take multiple files to
modify, how much difference (if any) is there in efficiency between

system call, pushing the array through xargs, but i'm sure the answer
would be "it depends on your machine".)

   tia,
   sweth.

--
Sweth Chandramouli
IS Coordinator, The George Washington University

<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>



Sun, 28 Jan 2001 03:00:00 GMT  
 chown -h

Quote:



>   if (($stats[0] != $lstats[0]) or ($stats[1] != $lstats[1])) {

It seems to me that

    if (! -l $file) {

would be much simpler here.

Quote:
>how much difference (if any) is there in efficiency between
>running each of chown (functions) separately, versus doing a `push



Probably not too much.  But the difference for the other branch of the
test, where a new process is spawned, is probably worth investigating.


Sun, 28 Jan 2001 03:00:00 GMT  
 chown -h

Quote:





>>   if (($stats[0] != $lstats[0]) or ($stats[1] != $lstats[1])) {

>It seems to me that

>    if (! -l $file) {

>would be much simpler here.

   doh!  i actually had the camel book open to the page on file test
operators while typing the above, but still somehow missed the -l
operator.
   i've tried working this into my script, but it doesn't seem to be doing
what i want.  here's the important chunk:

sub uid_find_action {
   if (! -l $File::Find::name) {

      ($uid == $from_uid) &&
      (chown $to_uid, $uid_tmp_array[5], $File::Find::name);
   } else {
      system ("chown","-h","$to_uid","$File::Find::name");
   };

Quote:
};

   this is the find_action subroutine for a find (from the File::find
module) that iterates across a hash of uids to map from/to.  the script
worked fine before, when the action was just the first portion of the if
loop, and for those files that aren't symlinks (and thus still use that
portion), things still work.   for the symlinks, however, the $to_uid var
that is being used for all of the system calls is the last one of the
hash, as opposed to the appropriate one for that particular iteration.  is
there any reason that $to_uid would change depending on which part of the
if logic above were matched?
   (if the problem doesn't look like it is in this particular chunk, and
you'd like to do me a huge favor, the entire script is at
<http://astaroth.nit.gwu.edu/~sweth/geek/mvid.pl>.  this was the only part
that was changed, though (i think), between working and not working.)

   -- sweth.

--
Sweth Chandramouli
IS Coordinator, The George Washington University

<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>



Mon, 29 Jan 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Please help! (CHOWN / Nobody)

2. Chown'ing a symbolic link

3. chown question

4. Need help learning how to use chown correclty inside of a perl script

5. Chown and SymLinks

6. Bug in chown ?

7. doing chmod, chown & chgrp from perl

8. 0 21 * * 5 root /bin/chown 444 /usr/sbin/sendmail

9. chown, but no lchown

10. How to chown and chmod

11. How to chown a symbolic link in Perl?

12. PERLFUNC: chown - change the owership on a list of files

 

 
Powered by phpBB® Forum Software