James Ponza said:

> 1. tell it to use a different partition for the portage tree

  Yes, you can do this. Look for PORTDIR, DISTDIR and PKGDIR in your
/etc/make.conf

> 2. tell it to clean up my portage tree (not the besst option since with
> around 2.2Gb of data downloaded from the net it'd be nice to preserve it
> somehow in case I ever needed it again).

  The distfiles directory is the real space hog. Below is a script someone
posted in the Gentoo Forums to clear away old versions in distfiles. I
changed the way old versions were detected (using the modification time
rather then version names which are inconsistent) and added a report on
the amount of space potentially saved. You have to run the script with
--nopretend for it to actually delete anything.

  *Note: Some packages actually use several versions of various files in
distfiles, so you may end up deleting something that will have to be
downloaded again at a later date...

  *Note: This script only looks at files ending in .tar.gz, .tgz and
.tar.bz2 so it misses quite a few files (ie Americas Army is a 680 Meg
.bin file, a couple of versions of this can waste a gig or two).

> 3. slim down the ports system? ie do I really need every single version
> of every port available? or do I just need one in each
> category/directory?...

  Most of these ~80000 files are part of the portage tree and are
automatically trimmed by your emerge sync when they are no longer
needed.


Cheers,
Malcolm V.

------------------- Script Below ------------------------
#!/usr/bin/perl -w
use strict;
use File::stat;

my $dirpath = "/usr/portage/distfiles";
my $lastname = 0;
my $lastversion;
my $lastmtime;
my $lastsize;
my $lastext;
my @stalefiles;
my @files;

# Insert your exclusions here with trailing '-'
my %maskedfiles = (
#   'X420src-' => 1,
#   'gcc-' => 1,
#   'freetype-' => 1
);

# Root check
if ($< != 0) {
  print "You must be root to run this script.\n";
  exit 0;
}

# Determine sources present on the system
print "Determining available tarballs in /usr/portage/distfiles ...\n";
opendir(DIR, $dirpath);
@files = sort(readdir(DIR));
closedir(DIR);

# Grab names/versions, checking each time whether current distfile
# has been superceded. Push anonymous array ref containing required
# info into @stalefiles array.
print "Determining stale versions ...\n";
foreach (@files) {
  my $name;
  my $version;
  my $info;

  # Only operate on tarballs
  if (/(.+?\-)([0-9r\.\-]+)(\.tar\.gz|\.tgz|\.tar.bz2)/s) {
    $name = $1;
    $version = $2;
    next if ($maskedfiles{$name}); # Ignore "masked" files
    $info = stat($dirpath."/".$_) || die "no stats for $dirpath/$_";
    if ($name eq $lastname) {
    if ($info->mtime > $lastmtime) {
        push (@stalefiles, [$name,
$version,$lastversion,$lastext,$lastsize]);
    }
    else {
        push (@stalefiles, [$name, $lastversion, $version, $3,$info->size]);
    }
    }
    $lastname = $name;
    $lastversion = $version;
    $lastsize = $info->size;
    $lastmtime = $info->mtime;
    $lastext = $3;
  }
}

if (@stalefiles == 0) {
  print "\nNo stale distfiles have been detected on your system!\n";
  exit 0;
}

if ($ARGV[0] && $ARGV[0] eq '--nopretend') {
  # User requested deletion so here goes ...
  print "*Nopretend* mode, deleting stale files:\n\n";
  foreach (@stalefiles) {
    my ($name, $version, $lastversion, $ext) = @{$_};
    unlink($dirpath . "/".$name . $lastversion . $ext);
    print "Deleted: $name$lastversion in favour of $name$version\n";
  }
}
else {
  # Safe mode (default)!
  print "\7*Pretend* mode, will only pretend to delete files.\nTo actually
delete the files, reinvoke with the --nopretend parameter.\n\n";
  my $totalsize=0;
  foreach (@stalefiles) {
    my ($name, $version, $lastversion, $ext,$size) = @{$_};
    print "Would delete: $name$lastversion in favour of $name$version\n";
    $totalsize += $size;
  }
  #Pretty Formatting
  my $saved_size = $totalsize/1024;
  my $saved_units = "k";
  my $saved_precision = 0;

  if ($saved_size > 512) {
    $saved_precision = 1;
    if ($saved_size > 1024*512) {
      $saved_size /= 1024*1024;
      $saved_units = "G";
    }
    else {
      $saved_size /= 1024;
      $saved_units = "M";
    }
  }
  printf "Space saving: %.*f
%sBytes\n",$saved_precision,$saved_size,$saved_units;
}
1;

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to