From 2e45477017b7093c9ad0d3f01d5d5990da841e5b Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Wed, 22 Sep 2004 07:38:07 +0000 Subject: Handle reading multiple "hdlists" files (for supplementary media) --- perl-install/pkgs.pm | 80 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/perl-install/pkgs.pm b/perl-install/pkgs.pm index e80497d5f..66f2569dd 100644 --- a/perl-install/pkgs.pm +++ b/perl-install/pkgs.pm @@ -343,14 +343,21 @@ sub unselectAllPackages($) { callback_choices => \&packageCallbackChoices); } +sub urpmidir { + my ($prefix) = @_; + my $v = "$prefix/var/lib/urpmi"; + -l $v && !-e _ and unlink $v and mkdir $v, 0755; #- dangling symlink + -w $v ? $v : '/tmp'; +} + sub psUpdateHdlistsDeps { my ($prefix, $_method, $packages) = @_; my $need_copy = 0; + my $urpmidir = urpmidir($prefix); #- check if current configuration is still up-to-date and do not need to be updated. foreach (values %{$packages->{mediums}}) { $_->{selected} || $_->{ignored} or next; - my $urpmidir = -w "$prefix/var/lib/urpmi" ? "$prefix/var/lib/urpmi" : "/tmp"; my $hdlistf = "$urpmidir/hdlist.$_->{fakemedium}.cz" . ($_->{hdlist} =~ /\.cz2/ && "2"); my $synthesisf = "$urpmidir/synthesis.hdlist.$_->{fakemedium}.cz" . ($_->{hdlist} =~ /\.cz2/ && "2"); if (-s $hdlistf != $_->{hdlist_size}) { @@ -366,22 +373,25 @@ sub psUpdateHdlistsDeps { if ($need_copy) { #- this is necessary for urpmi. - my $urpmidir = -w "$prefix/var/lib/urpmi" ? "$prefix/var/lib/urpmi" : "/tmp"; install_any::getAndSaveFile("Mandrake/base/$_", "$urpmidir/$_") foreach qw(rpmsrate); } } sub psUsingHdlists { - my ($prefix, $method) = @_; - my $listf = install_any::getFile('Mandrake/base/hdlists') or die "no hdlists found"; - my $packages = new URPM; + my ($o, $method, $o_hdlistsprefix, $o_packages, $o_initialmedium, $o_callback) = @_; + my $prefix = $o->{prefix}; + my $listf = install_any::getFile($o_hdlistsprefix ? "$o_hdlistsprefix/Mandrake/base/hdlists" : 'Mandrake/base/hdlists') + or die "no hdlists found"; my $suppl_CDs = 0; - - #- add additional fields used by DrakX. - @$packages{qw(count mediums)} = (0, {}); + if (!$o_packages) { + $o_packages = new URPM; + #- add additional fields used by DrakX. + @$o_packages{qw(count mediums)} = (0, {}); + } #- parse hdlists file. - my $medium = 1; + my $medium_name = $o_initialmedium || 1; + my @hdlists; foreach (<$listf>) { chomp; s/\s*#.*$//; @@ -389,33 +399,37 @@ sub psUsingHdlists { #- we'll ask afterwards for supplementary CDs, if the hdlists file contains #- a line that begins with "suppl" if (/^suppl/) { $suppl_CDs = 1; next } + my $cdsuppl = index($medium_name, 's') >= 0; m/^\s*(noauto:)?(hdlist\S*\.cz2?)\s+(\S+)\s*(.*)$/ or die qq(invalid hdlist description "$_" in hdlists file); + push @hdlists, [ $2, $medium_name, $3, $4, !$1, + #- hdlist path, suppl CDs are mounted on /mnt/cdrom : + $o_hdlistsprefix ? "$o_hdlistsprefix/Mandrake/base/$2" : undef, + ]; + $cdsuppl ? ($medium_name = ($medium_name + 1) . 's') : ++$medium_name; + } + foreach my $h (@hdlists) { #- make sure the first medium is always selected! #- by default select all image. - psUsingHdlist($prefix, $method, $packages, $2, $medium, $3, $4, !$1); - - ++$medium; + my $supplmedium = psUsingHdlist($prefix, $method, $o_packages, @$h); + $o_callback and $o_callback->($supplmedium, $o_hdlistsprefix, $method); } - log::l("psUsingHdlists read " . int(@{$packages->{depslist}}) . - " headers on " . int(keys %{$packages->{mediums}}) . " hdlists"); + log::l("psUsingHdlists read " . int(@{$o_packages->{depslist}}) . + " headers on " . int(keys %{$o_packages->{mediums}}) . " hdlists"); - return ($packages, $suppl_CDs); + return $o_packages, $suppl_CDs; } sub psUsingHdlist { - my ($prefix, $method, $packages, $hdlist, $medium, $rpmsdir, $descr, $selected, $o_fhdlist, $o_pubkey) = @_; - my $fakemedium = "$descr ($method$medium)"; - my $urpmidir = -w "$prefix/var/lib/urpmi" ? "$prefix/var/lib/urpmi" : "/tmp"; - log::l("trying to read $hdlist for medium $medium"); - - #- if the medium already exist, use it. - $packages->{mediums}{$medium} and return $packages->{mediums}{$medium}; + my ($prefix, $method, $packages, $hdlist, $medium_name, $rpmsdir, $descr, $selected, $o_fhdlist, $o_pubkey) = @_; + my $fakemedium = "$descr ($method$medium_name)"; + my $urpmidir = urpmidir($prefix); + log::l("trying to read $hdlist for medium $medium_name"); my $m = { hdlist => $hdlist, method => $method, - medium => $medium, + medium => $medium_name, rpmsdir => $rpmsdir, #- where is RPMS directory. descr => $descr, fakemedium => $fakemedium, @@ -432,11 +446,17 @@ sub psUsingHdlist { $m->{hdlist_size} = -s $newf; #- keep track of size for post-check. symlinkf $newf, "/tmp/$hdlist"; - #- if $o_fhdlist is defined, this is preferable not to try to find the associated synthesis. my $newsf = "$urpmidir/synthesis.hdlist.$fakemedium.cz" . ($hdlist =~ /\.cz2/ && "2"); - unless ($o_fhdlist) { + #- if $o_fhdlist is a filehandle, it's preferable not to try to find the associated synthesis. + if (!ref $o_fhdlist) { #- copy existing synthesis file too. - install_any::getAndSaveFile("Mandrake/base/synthesis.$hdlist", $newsf); + my $synth; + if ($o_fhdlist) { + $synth = $o_fhdlist; + $synth =~ s/hdlist/synthesis.hdlist/ or $synth = undef; + } + $synth ||= "Mandrake/base/synthesis.$hdlist"; + install_any::getAndSaveFile($synth, $newsf); $m->{synthesis_hdlist_size} = -s $newsf; #- keep track of size for post-check. -s $newsf > 0 or unlink $newsf; } @@ -618,19 +638,19 @@ sub saveCompssUsers { } } } - my $urpmidir = -w "$prefix/var/lib/urpmi" ? "$prefix/var/lib/urpmi" : "/tmp"; + my $urpmidir = urpmidir($prefix); output "$urpmidir/compssUsers.flat", $flat; } sub setSelectedFromCompssList { - my ($packages, $compssUsersChoice, $min_level, $max_size) = @_; - $compssUsersChoice->{TRUE} = 1; #- ensure TRUE is set + my ($packages, $rpmsrate_flags_chosen, $min_level, $max_size) = @_; + $rpmsrate_flags_chosen->{TRUE} = 1; #- ensure TRUE is set my $nb = selectedSize($packages); foreach my $p (sort { $b->rate <=> $a->rate } @{$packages->{depslist}}) { my @flags = $p->rflags; next if !$p->rate || $p->rate < $min_level || - any { !any { /^!(.*)/ ? !$compssUsersChoice->{$1} : $compssUsersChoice->{$_} } split('\|\|') } @flags; + any { !any { /^!(.*)/ ? !$rpmsrate_flags_chosen->{$1} : $rpmsrate_flags_chosen->{$_} } split('\|\|') } @flags; #- determine the packages that will be selected when #- selecting $p. the packages are not selected. -- cgit v1.2.1