joachim99@14: #! /usr/bin/perl joachim99@14: joachim99@14: # joachim99@14: # This script recursively (beginning with the current directory) joachim99@14: # wipes out everything not registered in CVS. joachim99@14: # joachim99@14: # written by Oswald Buddenhagen joachim99@14: # inspired by the "old" cvs-clean target from Makefile.common joachim99@14: # joachim99@14: # This file is free software in terms of the BSD licence. That means joachim99@14: # that you can do anything with it except removing this license or joachim99@14: # the above copyright notice. There is NO WARRANTY of any kind. joachim99@14: # joachim99@14: joachim99@14: sub rmrf() joachim99@14: { joachim99@14: my $fn = shift; joachim99@14: lstat ($fn); joachim99@14: if (-d _) { joachim99@14: if (opendir (DIR, $fn)) { joachim99@14: for my $efn (grep (!/^\.\.?$/, readdir (DIR))) { joachim99@14: &rmrf ($fn."/".$efn); joachim99@14: } joachim99@14: closedir (DIR); joachim99@14: rmdir ($fn); joachim99@14: } joachim99@14: } else { joachim99@14: unlink ($fn); joachim99@14: } joachim99@14: } joachim99@14: joachim99@14: sub newfiles() joachim99@14: { joachim99@14: my ($indir, $incvs) = @_; joachim99@14: for my $n (keys (%$incvs)) { delete $$indir{$n} } joachim99@14: return sort (keys (%$indir)); joachim99@14: } joachim99@14: joachim99@14: sub cvsclean() joachim99@14: { joachim99@14: my $dir = shift; joachim99@14: my (%dirsdir, %filesdir, %dirscvs, %filescvs); joachim99@14: my $dnam = $dir ? $dir : "."; joachim99@14: if (!opendir (DIR, $dnam)) { joachim99@14: print STDERR "Cannot enter \"".$dnam."\".\n"; joachim99@14: return; joachim99@14: } joachim99@14: for my $fn (grep (!/^\.\.?$/, readdir (DIR))) { joachim99@14: if (-d $dir.$fn) { joachim99@14: $fn eq "CVS" or $dirsdir{$fn} = 1; joachim99@14: } else { joachim99@14: $filesdir{$fn} = 1; joachim99@14: } joachim99@14: } joachim99@14: closedir (DIR); joachim99@14: if (!open (FILE, "<".$dir."CVS/Entries")) { joachim99@14: print STDERR "No CVS information in \"".$dnam."\".\n"; joachim99@14: return; joachim99@14: } joachim99@14: while () { joachim99@14: m%^D/([^/]+)/.*$% and $dirscvs{$1} = 1; joachim99@14: m%^/([^/]+)/.*$% and $filescvs{$1} = 1; joachim99@14: } joachim99@14: close (FILE); joachim99@14: if (open (FILE, "<".$dir."CVS/Entries.Log")) { joachim99@14: while () { joachim99@14: m%^A D/([^/]+)/.*$% and $dirscvs{$1} = 1; joachim99@14: m%^A /([^/]+)/.*$% and $filescvs{$1} = 1; joachim99@14: m%^R D/([^/]+)/.*$% and delete $dirscvs{$1}; joachim99@14: m%^R /([^/]+)/.*$% and delete $filescvs{$1}; joachim99@14: } joachim99@14: close (FILE); joachim99@14: } joachim99@14: for my $fn (&newfiles (\%filesdir, \%filescvs)) { joachim99@14: print ("F ".$dir.$fn."\n"); joachim99@14: &rmrf ($dir.$fn); joachim99@14: } joachim99@14: for my $fn (&newfiles (\%dirsdir, \%dirscvs)) { joachim99@14: print ("D ".$dir.$fn."\n"); joachim99@14: &rmrf ($dir.$fn); joachim99@14: } joachim99@14: for my $fn (sort (keys (%dirscvs))) { joachim99@14: &cvsclean ($dir.$fn."/"); joachim99@14: } joachim99@14: } joachim99@14: joachim99@14: &cvsclean ("");