SPUG: Fixing Cygwin broken links
Aaron West
tallpeak at hotmail.com
Thu Jul 21 17:02:25 PDT 2005
perldoc -f stat says "use Fcntl ':mode';" for those constants. Oops. I
didn't do that.
And I didn't use -w. I know, I'm bad.
The expression apparently reduced to true, and it looks at all files under
200 bytes.
$ perl -lwe 'use Fcntl ":mode"; $x=S_IFREG; print $x'
32768
$ perl -lwe '$mode=0; print +(($mode & (S_IFREG | S_IFLNK)) == S_IFREG)'
Argument "S_IF^OO" isn't numeric in bitwise and (&) at -e line 1.
Argument "S_IFREG" isn't numeric in numeric eq (==) at -e line 1.
1
S_IFREG is a string. S_IFREG | S_IFLNK is a bitwise or of two strings.
Okay, I'll try to remember -w even for little "hacks".
This is cleaner (though some warnings about unused variables from stat):
$ cat ./fixlinks.pl
#!perl -w
$|=1;
use Fcntl ':mode';
while($filename = <*>)
{
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
if (defined $size && $size > 9 && $size < 200 && $mode & S_IFREG )
{
unless (open FH, "<$filename")
{
print "Can't open $filename\n";
next;
}
$firstline = <FH>;
close FH;
chomp $firstline;
if ($firstline =~ /^\!\<symlink\>(.*)/)
{
print "ln -sf $1 $filename\n"; #inform the user what
is effectively happening
unlink $filename;
symlink $1, $filename;
}
}
}
----- Original Message -----
From: "Michael R. Wolf" <MichaelRWolf at att.net>
To: "'Aaron West'" <tallpeak at hotmail.com>; <spug-list at pm.org>
Sent: Thursday, July 21, 2005 12:11 PM
Subject: RE: SPUG: Fixing Cygwin broken links
> What are the S_* constants? How did you get them loaded?
>
>
>
>> if ($size < 200 && (($mode & (S_IFREG | S_IFLNK)) == S_IFREG) )
>
> A DeMorgan equivalent should be:
> if ($size < 200 && $mode & S_IFREG )
>
> But that doesn't seem to be saying what you claim that it's doing.
>
>
>
>
>
More information about the spug-list
mailing list