From 440ffe22ded3de7604e00d6c98e24e1069ebf378 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 20 Mar 2008 01:17:08 +0000 Subject: move functions to get available space from installer to drakxtools (to be used in draklive-install) --- perl-install/fs/any.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'perl-install/fs') diff --git a/perl-install/fs/any.pm b/perl-install/fs/any.pm index d523a6943..730252b40 100644 --- a/perl-install/fs/any.pm +++ b/perl-install/fs/any.pm @@ -104,4 +104,39 @@ sub prepare_minimal_root { } } +sub getAvailableSpace { + my ($fstab) = @_; + + #- make sure of this place to be available for installation, this could help a lot. + #- currently doing a very small install use 36Mb of postinstall-rpm, but installing + #- these packages may eat up to 90Mb (of course not all the server may be installed!). + #- 65mb may be a good choice to avoid almost all problem of insuficient space left... + my $minAvailableSize = 65 * sqr(1024); + + my $n = !$::testing && getAvailableSpace_mounted($::prefix) || + getAvailableSpace_raw($fstab) * 512 / 1.07; + $n - max(0.1 * $n, $minAvailableSize); +} + +sub getAvailableSpace_mounted { + my ($prefix) = @_; + my $dir = -d "$prefix/usr" ? "$prefix/usr" : $prefix; + my (undef, $free) = MDK::Common::System::df($dir) or return; + log::l("getAvailableSpace_mounted $free KB"); + $free * 1024 || 1; +} +sub getAvailableSpace_raw { + my ($fstab) = @_; + + do { $_->{mntpoint} eq '/usr' and return $_->{size} } foreach @$fstab; + do { $_->{mntpoint} eq '/' and return $_->{size} } foreach @$fstab; + + if ($::testing) { + my $nb = 450; + log::l("taking ${nb}MB for testing"); + return MB($nb); + } + die "missing root partition"; +} + 1; -- cgit v1.2.1