#!/usr/bin/perl use Getopt::Std; use File::Basename; getopts('pvhldsf'); # Step 1: create a list of ALL files in portage, dupecheck # Step 2: list files in /usr/portage/distfiles that aren't on the above list # Step 3: optionally delete those files $distfilesdir = "/usr/portage/distfiles"; $portagecachedir = "/var/cache/edb/dep"; if($opt_h || !($opt_p || $opt_d || $opt_l || $opt_f)) { $opt_d=$opt_h; # I'm too lazy to make this not warn about $opt_h being $opt_p=$opt_h; # used once the "proper" way... print STDERR "Usage: $0 [OPTION]...\n"; print STDERR "What does this program do?\n\n"; print STDERR " -d Delete old files that are no longer needed in $distfilesdir\n"; print STDERR " -p List old files that would be deleted if -d was used\n"; print STDERR " -sl List all of the possible files in $distfilesdir\n"; print STDERR " -l List all of the possible files in $distfilesdir and show\n"; print STDERR " one of the packages that uses it\n"; print STDERR " -f List all of the files missing that should be there\n"; print STDERR " for a mirror\n"; print STDERR " -v Verbose Mode\n"; print STDERR " -h Display this help and exit\n"; print STDERR "\nReport bugs to .\n"; exit; } if ((!-d $portagecachedir) || (!-d $distfilesdir)) { print "I can\'t find either $distfilesdir or $portagecachedir\n"; print "I\'m designed for gentoo's portage ;)\n"; exit; } opendir(DIR, $portagecachedir); my @sections=sort(readdir(DIR)); closedir(DIR); %philes = (); foreach (@sections) { if(!/^\./) { my $section=$_; if ($opt_v) { print "$section\n"; } opendir(DIR, "$portagecachedir/$section"); my @ebuilds=sort(readdir(DIR)); closedir(DIR); foreach (@ebuilds) { if(!/^\./) { my $ebuild=$_; if ($opt_v) { print "$section/$ebuild\n"; } open(FILE, "$portagecachedir/$section/$ebuild"); my @mom = ; close(FILE); $temp=join("", @mom); @mom = split(/\n/,$temp); #chomp(@mom); #print $mom[3]; @files = split(/ /,$mom[3]); foreach(@files) { # dont do things that are (, ) or end with a ? because thats part of # portages logic if (!/^\(/ && !/^\)/ && !/\?$/) { $temp=basename($_); $philes{$temp} = "$ebuild"; } } } } } } if ($opt_l) { @keys = sort keys %philes; foreach (@keys) { if (!$opt_s) { print $philes{$_} . ": "; } print "$_\n"; } $opt_l=$opt_l; } elsif ($opt_p || $opt_d) { opendir(DIR, $distfilesdir); my @files = readdir(DIR); closedir(DIR); foreach(@files) { if (!/^\./ && !$philes{$_} && !-d "$distfilesdir/$_") { $yayflag=1; if ($opt_d) { unlink($distfilesdir."/".$_); } else { print "$_\n"; } } } if (!$yayflag) { print "Nothing found to remove\n"; } } elsif ($opt_f) { opendir(DIR, $distfilesdir); my @files = readdir(DIR); closedir(DIR); %filelist = (); foreach(@files) { $filelist{$_} = "lo"; } @keys = sort keys %philes; foreach(@keys) { if (!/^\./ && !$filelist{$_} && !-d "$distfilesdir/$_") { $yayflag=1; print "$_\n"; } } if (!$yayflag) { print STDERR "Nothing found to download!\n"; 1; } }