Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Optionally changing file perms?
God, I hate bit math!  I just can't get my mind around it..

I'm trying to identify new file modes for a variety of
files and directories on a given system.  The first step is
to ensure directories have execute permissions if the appropriate
read permission is set.  For instance, if a directory has
0660 permissions, I want to change the mode to 0770.

Here's what I have so far:

<<snip>>
open (In, "< $wws") || die "Can't read $wws - ($!)";
while (<In> )
{  chomp;
my $file = $_;
next if (! -d $file && ! -f $file); #ensure we're looking at dirs/files
my ($fmode, $fuid) = (stat($file))[2,4];
my $pmode = $fmode;
if ( -d $file)
{  # ;;
$pmode |= S_IXUSR ; # if ($pmode & S_IRUSR);
# $pmode |= S_IXGRP if ($pmode & S_IRGRP);
# $pmode |= S_IXOTH if ($pmode & S_IROTH);
}
# next if (! defined(${$uids}{$fuid}));
printf ("%04o %04o %s\n", $fmode & 07777,  $pmode & 07777, $file);
}

When I run the script, the $pmode is all 0's:

# ./filter biteme
1777 0000 /tmp
0666 0000 ./testies

If I comment out the $pmode change, $pmode is the same as $fmode,
as I would expect...

if ( -d $file)
{  ;;
# $pmode |= S_IXUSR ; # if ($pmode & S_IRUSR);
# $pmode |= S_IXGRP if ($pmode & S_IRGRP);
# $pmode |= S_IXOTH if ($pmode & S_IROTH);
}

# ./filter biteme
1777 1777 /tmp
0666 0666 ./testies

I hate being such an idiot that I can't figure out a simple concept,
but can someone point out what I'm doing wrong?

Thanks.

Doug


--
--------
Senior UNIX Admin
O'Leary Computer Enterprises
dkoleary@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume:  http://home.comcast.net/~dkoleary/resume.html


Report this thread to moderator Post Follow-up to this message
Old Post
Doug O'Leary
09-23-04 08:58 PM


Re: Optionally changing file perms?
In article <sdA4d.2105$o06.1757@news.flashnewsgroups.com>,
Doug O'Leary  <dkoleary@olearycomputers.com> wrote:

: Here's what I have so far:
:
: <<snip>>
: open (In, "< $wws") || die "Can't read $wws - ($!)";
: while (<In> )
: {  chomp;
:    my $file = $_;
:    next if (! -d $file && ! -f $file);
:    my ($fmode, $fuid) = (stat($file))[2,4];
:    my $pmode = $fmode;
:    if ( -d $file)
:    {  # ;;
:       $pmode |= S_IXUSR ; # if ($pmode & S_IRUSR);
:       # $pmode |= S_IXGRP if ($pmode & S_IRGRP);
:       # $pmode |= S_IXOTH if ($pmode & S_IROTH);
:    }
:    # next if (! defined(${$uids}{$fuid}));
:    printf ("%04o %04o %s\n", $fmode & 07777,  $pmode & 07777, $file);
: }
:
: When I run the script, the $pmode is all 0's:
:
: # ./filter biteme
: 1777 0000 /tmp
: 0666 0000 ./testies

I can't reproduce that result:

$ cat try
#! /usr/local/bin/perl

use warnings;
use strict;

use Fcntl ":mode";

while (<DATA> )
{  chomp;
my $file = $_;
next if (! -d $file && ! -f $file);
my ($fmode, $fuid) = (stat($file))[2,4];
my $pmode = $fmode;
if ( -d $file)
{  # ;;
$pmode |= S_IXUSR ; # if ($pmode & S_IRUSR);
# $pmode |= S_IXGRP if ($pmode & S_IRGRP);
# $pmode |= S_IXOTH if ($pmode & S_IROTH);
}
# next if (! defined(${$uids}{$fuid}));
printf ("%04o %04o %s\n", $fmode & 07777, $pmode & 07777, $file);
}

__DATA__

Report this thread to moderator Post Follow-up to this message
Old Post
Greg Bacon
09-23-04 08:58 PM


Re: Optionally changing file perms?
On 2004-09-23, Greg Bacon <gbacon@hiwaay.net> wrote:
>
> I can't reproduce that result:
>
>     0660 0760 ./foo
>     0770 0770 ./bar
>
> Hmm.. did you import the S_I* symbols using the Fcntl module?  Is
> perl treating them as barewords in your program, in other words?

Well, it's good to know the logic is correct.  I tried doing
the use Fcntl thing; however, I get a core dump on my HP 11.00 perl
v5.6.  While browing through documentation, I found
use POSIX ":fcntl_h".  My half-formed thought was that the POSIX
module was Fcntl's successor.  POSIX *seemed* to work - at least it
compiled and ran.  Apparently, those constants aren't defined...

I'll see about finding what the constants are defined as in the
fcntl module and use them directly.

Thanks for your help, I appreciate it.

Doug

--
--------
Senior UNIX Admin
O'Leary Computer Enterprises
dkoleary@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume:  http://home.comcast.net/~dkoleary/resume.html


Report this thread to moderator Post Follow-up to this message
Old Post
Doug O'Leary
09-24-04 01:58 AM


Re: Optionally changing file perms?
Doug O'Leary  <dkoleary@olearycomputers.com> wrote in comp.lang.perl.misc:
> On 2004-09-23, Greg Bacon <gbacon@hiwaay.net> wrote: 
>
> Well, it's good to know the logic is correct.  I tried doing
> the use Fcntl thing; however, I get a core dump on my HP 11.00 perl
> v5.6.  While browing through documentation, I found
> use POSIX ":fcntl_h".  My half-formed thought was that the POSIX
> module was Fcntl's successor.  POSIX *seemed* to work - at least it
> compiled and ran.  Apparently, those constants aren't defined...

They are, but strangely not all of them under the ":fcntl_h" tag.
Some are in ":sys_stat_h".  Request both, or just "use POSIX;"
without qualification to get them all.

Anno

Report this thread to moderator Post Follow-up to this message
Old Post
Anno Siegel
09-29-04 04:02 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:24 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.