Bug#37999: PROPOSED]: A pre-install required space checking mechanism for Debian packages
Hi,
Look at this script:
#! /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;
--
For every credibility gap, there is a gullibility fill. Clopton
Manoj Srivastava <srivasta@debian.org> <http://www.debian.org/%7Esrivasta/>
Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E
Reply to: