home *** CD-ROM | disk | FTP | other *** search
/ ftp.urbanrage.com / 2015-02-07.ftp.urbanrage.com.tar / ftp.urbanrage.com / pub / perl / cvs_fixroot.pl < prev    next >
Perl Script  |  2002-04-21  |  1KB  |  55 lines

  1. #!/usr/bin/perl
  2.  
  3. use Fcntl ':mode';
  4.  
  5. if (scalar(@ARGV) == 0) {
  6.     print "usage: $0 top_directory [top_directory .. ]\n";
  7.     print "\tThis programs replaces the information in the Root files in a\n";
  8.     print "\tlocal cvs repository with what is currently in your CVSROOT\n";
  9.     print "\tenvironment variable.\n";
  10.     print "\tYour current CVSROOT is $ENV{CVSROOT}\n";
  11.     exit(0);
  12. }
  13.        
  14. foreach $dir (@ARGV) {
  15.     do_dir($dir);
  16. }
  17.  
  18. exit(0);
  19.  
  20. sub do_dir {
  21.     my $prefix = shift;
  22.  
  23.     return if $prefix eq "CVS"; 
  24.     return if $prefix =~ /\/CVS$/;
  25.  
  26.     print "Working on Directory: $prefix\n";    
  27.  
  28.     opendir (DIR, $prefix) or do {
  29.     print "Couldn't open $prefix : $! : skipping\n";
  30.     return;
  31.     };
  32.     my @files = grep !/^\.\.?$/, readdir DIR;
  33.     closedir DIR;
  34.     if ( -e $prefix."/CVS/Root") { # it exists, nuke it
  35.     if (!open(CVS, ">${prefix}/CVS/Root")) {
  36.         print "Couldn't open ${prefix}/CVS/Root : $!\n";
  37.     } else {
  38.         print CVS "$ENV{CVSROOT}\n";
  39.         close CVS;
  40.     }
  41.     }
  42.     my $file;
  43.     foreach $file (@files) {
  44.     next if $file eq "CVS";
  45.     my $path = join("/", $prefix, $file);
  46.  
  47.     my $type = (lstat($path))[2];
  48.     next if S_ISLNK($type);
  49.  
  50.     if ( -d $path ) {
  51.         do_dir($path);
  52.     }
  53.     }
  54. }
  55.