SPUG: Fixing Cygwin broken links

Aaron West tallpeak at hotmail.com
Thu Jul 21 05:30:31 PDT 2005


If you find your Cygwin links don't work (eg. some commands do nothing or get stuck in a loop):

For some reason, my latest Cygwin install created nonworking links. So I converted each tiny file containing <symlink> at the start to a real symlink. It's simple enough to write that I'm not sure it's worth posting, nor if anyone else has seen this same problem, but here it is. There's no error-checking; use at your own risk. 200 is arbitrary, and a bit large, but it seems reasonably safe to assume that a file starting with <symlink> less than 200 bytes is supposed to be a symlink (not a regular file).

$ cd / ; find . -xdev -name "*bin" -type d  -exec sh -c 'echo {}; cd {}; fixlinks.pl' \;

$ cat /usr/bin/fixlinks.pl
#!perl
while($filename = <*>)
{
        ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
           $atime,$mtime,$ctime,$blksize,$blocks)
                = stat($filename);
        if ($size < 200 && (($mode & (S_IFREG | S_IFLNK)) == S_IFREG) )
        {
                open FH, "<$filename";
                $firstline = <FH>;
                close FH;
                chomp $firstline;
                if ($firstline =~ /^\!\<symlink\>(.*)/)
                {
                        print "ln -s $1 $filename\n";
                        unlink $filename;
                        symlink $1, $filename;
                }
        }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20050721/698cc272/attachment-0001.html


More information about the spug-list mailing list