[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: New APT version



Hi,

	Here follows a checkdu script that can be used for this. This
 needs the output of a du -S (not the old helper script output,
 that was suboptimal, since there the data format was designed
 before the application)

	This works quite well, as it looks at what df says, and parses
 that, instead of relying on hueristics.

	All we need now is policy asking packages to include a Sizes
 file in the DEBIAN subdir, and then arrange apt to run something like
 this script.

	Mind you, I can do better with more time spent on this ;-)
 this is currently a pretty minimalist class.

	manoj

______________________________________________________________________
#! /usr/bin/perl -w

package Check_DU;

use strict;
use diagnostics;
use Carp;
require 5.001;

sub check_du {
  my %data;
  
  # find out the mount points of the devices
  open DF, "df |" or die "Could not run df:$!" ;
  while (<DF>) {
    m!/dev.*\s(/\S*)! or next;
    my $device_no = (stat($1))[0];
    $data{$device_no}{'Name'} = $1;
  }
  close DF or die "Could not close pipe from df:$!" ;
  
  # read all the du -S files given on the command line
  while (<>) {
    my ($size, $dir_name) = split /\s+/, $_;
    my $device_no = (stat("/$dir_name"))[0];
    $data{$device_no}{'Size'} += $size;
  }
  return \%data;
}

sub print_du {
  my %params = @_;
  croak("Need argument 'Size Data'") unless defined $params{'Size Data'};
  
  
  for (sort keys %{$params{'Size Data'}}) {
    next unless $params{'Size Data'}{$_}{'Size'};
    printf "%10d %s\n", $params{'Size Data'}{$_}{'Size'}, 
                        $params{'Size Data'}{$_}{'Name'};
  }
}

sub test_du {
  my $data = &check_du();
  &print_du('Size Data' => $data);
}

{ # Execute simple test if run as a script
  package main; no strict;
  eval join('',<main::DATA>) || die "$@ $main::DATA" unless caller();
}


1;

__END__

# Test the library
&Check_DU::test_du();

1;

-- 
 Though one were to live a hundred years without seeing the deathless
 state, the life of a single day is better if one sees the deathless
 state. 114
Manoj Srivastava  <srivasta@acm.org> <http://www.datasync.com/%7Esrivasta/>
Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05  CC 2D 27 12 1D F5 E8 6E


--
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: