Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
dupbuster (for distfiles)
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 20 Sep 2002
Posts: 171

PostPosted: Mon Jan 12, 2004 10:40 pm    Post subject: dupbuster (for distfiles) Reply with quote

hi below is a script based on discussuion in this thread
for cleaning distfiles directory from all .tgz,tbz... for packges not installed
on the machine...
But I wanted a version that removes ONLY FILE FOR OLD VERSIONS OF THE PACKAGES i.e. the newest FILES are preserved.
The idea is to get rid of really unnececary files... why I will need such thing ?
other distfiles-cleaners didint worked for me 'cause I have several Gentoo boxes which I sync from time to time.. i.e. I may install pkg X on machine A then sync A->B.
Even that I dont have pkg X installed on B(I may decide to install it later),
it wont be deleted. So possibly saving repeating the same dload from Internet.

U have to run the script with "-p" option, so no action is done...
like emerge -p.
If u didnt specify option the files will not be deleted, but instead moved to
/usr/portage/olddist where u can take final look before deletion...

The sequence is :

#dupbuster -p
#du -shc /usr/portage/distfiles
#du -shc /usr/portage/distfiles
#du -shc /usr/portage/olddist

It doesnt save alot space as distcleaners, but removes things
that are really unnececary anymore..


use Getopt::Std;
use Data::Dumper;
my %makeconf;
my %dups;
$makeconf{"PORTDIR"} = '/usr/portage';
$makeconf{"DISTDIR"} = '/usr/portage/distfiles';
sub get_make_conf {
  my ($var);
  open (MAKECONF, "</etc/make.conf");
  while(<MAKECONF>) {
    if (/^\s*(\w+)=(.+)$/) {
  # simple hack to expand the shell variables
  foreach $var (keys %makeconf) {
    my ($sub);
    while ($makeconf{$var}=~/"?\$\{(\w+)\}"?/) {
print "PORTDIR = ".$makeconf{"PORTDIR"}."\n";
print "DISTDIR = ".$makeconf{"DISTDIR"}."\n";
print "PORTDIR_OVERLAY = ".$makeconf{"PORTDIR_OVERLAY"}."\n";
#open(PACKAGES,"qpkg -v -I -nc |") || die "Can't list packages\n";
open(PACKAGES,"qpkg --dups -v -nc | sort -r |") || die "Can't list packages\n";
while(<PACKAGES>) {
  $package = $_;
  $package =~ m|(.*)/(.*)-(\d.*)|;
  $category = $1;
  $program = $2;
  $version = $3;
  unless ($dups{$program}) {
    $dups{$program} = 1 ;
    print "newest pkg : $program-$version\n" if $opt_p;
  print "old pkg : $program-$version\n" if $opt_p;
  $digest = $makeconf{"PORTDIR"}."/$category/$program/files/digest-$program-$version";
  if ($makeconf{"PORTDIR_OVERLAY"} && ! -f $digest) {
    $digest = $makeconf{"PORTDIR_OVERLAY"}."/$category/$program/files/digest-$program-$version";
  if (-f $digest) {
    open (DIGEST, "<$digest");
    while(<DIGEST>) {
      ($hashtype, $hash, $file, $size) = split;
if (scalar(keys(%files))==0) {
  die "sanity check: no package files found.  This can't be right.\n";
#print Dumper \%dups;
opendir(DIR,$makeconf{"DISTDIR"})|| die "can't open ".$makeconf{"DISTDIR"};
mkdir "/usr/portage/olddist";
while ($file = readdir DIR) {
  next unless -f $makeconf{"DISTDIR"}."/$file";
  if  ($files{$file}) {
    if ($opt_p) {
#      print "Would erase ".$makeconf{"DISTDIR"}."/$file\n";
      print "Would move  $makeconf{DISTDIR}/$file -> /usr/portage/olddist \n";
    else {
#      unlink $makeconf{"DISTDIR"}."/$file";
       rename "$makeconf{DISTDIR}/$file", "/usr/portage/olddist/$file";
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum