Warning, /sdk/kde-dev-scripts/cvs-clean is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env perl 0002 0003 # 0004 # This script recursively (beginning with the current directory) 0005 # wipes out everything not registered in CVS. 0006 # 0007 # written by Oswald Buddenhagen <ossi@kde.org> 0008 # inspired by the "old" cvs-clean target from Makefile.common 0009 # 0010 # This file is free software in terms of the modified BSD licence. 0011 # See kdelibs/doc/common/bsd-license.html for the exact conditions. 0012 # 0013 0014 use File::Path; 0015 0016 my $dry_run = 0; 0017 0018 sub newfiles() 0019 { 0020 my ($indir, $incvs) = @_; 0021 for my $n (keys (%$incvs)) { delete $$indir{$n} } 0022 return sort (keys (%$indir)); 0023 } 0024 0025 sub cvsclean() 0026 { 0027 my $dir = shift; 0028 my (%dirsdir, %filesdir, %dirscvs, %filescvs); 0029 my $dnam = $dir ? $dir : "."; 0030 if (!opendir (DIR, $dnam)) { 0031 print STDERR "Cannot enter \"".$dnam."\".\n"; 0032 return; 0033 } 0034 for my $fn (grep (!/^\.\.?$/, readdir (DIR))) { 0035 if (-d $dir.$fn) { 0036 $fn eq "CVS" or $dirsdir{$fn} = 1; 0037 } else { 0038 $filesdir{$fn} = 1; 0039 } 0040 } 0041 closedir (DIR); 0042 if (!open (FILE, "<".$dir."CVS/Entries")) { 0043 print STDERR "No CVS information in \"".$dnam."\".\n"; 0044 return; 0045 } 0046 while (<FILE>) { 0047 m%^D/([^/]+)/.*$% and $dirscvs{$1} = 1; 0048 m%^/([^/]+)/.*$% and $filescvs{$1} = 1; 0049 } 0050 close (FILE); 0051 if (open (FILE, "<".$dir."CVS/Entries.Log")) { 0052 while (<FILE>) { 0053 m%^A D/([^/]+)/.*$% and $dirscvs{$1} = 1; 0054 m%^A /([^/]+)/.*$% and $filescvs{$1} = 1; 0055 m%^R D/([^/]+)/.*$% and delete $dirscvs{$1}; 0056 m%^R /([^/]+)/.*$% and delete $filescvs{$1}; 0057 } 0058 close (FILE); 0059 } 0060 for my $fn (&newfiles (\%filesdir, \%filescvs)) { 0061 print ("F ".$dir.$fn."\n"); 0062 unlink($dir.$fn) unless $dry_run; 0063 } 0064 for my $fn (&newfiles (\%dirsdir, \%dirscvs)) { 0065 print ("D ".$dir.$fn."\n"); 0066 rmtree($dir.$fn, 0, 0) unless $dry_run; 0067 } 0068 for my $fn (sort (keys (%dirscvs))) { 0069 &cvsclean ($dir.$fn."/"); 0070 } 0071 } 0072 0073 my $usage = 0074 "usage: cvs-clean [options]\n". 0075 " --help | -h print usage information\n". 0076 " --dry-run | -n print intended actions; don't change filesystem\n"; 0077 0078 foreach my $arg (@ARGV) { 0079 if ($arg eq '-h' || $arg eq '--help') { 0080 print $usage; 0081 exit (0); 0082 } elsif ($arg eq '-n' || $arg eq '--dry-run') { 0083 $dry_run = 1; 0084 } else { 0085 print STDERR "cvs-clean: unknown argument '".$arg."'\n\n".$usage; 0086 exit (1); 0087 } 0088 } 0089 0090 &cvsclean ("");