From 89e7eee29e58c218e9546bf719590590b621485a Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 20 Aug 2008 16:29:23 +0000 Subject: create _search_packages_keep_best() out of _search_packages() --- urpm/select.pm | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/urpm/select.pm b/urpm/select.pm index eb8587ed..bb5302c6 100644 --- a/urpm/select.pm +++ b/urpm/select.pm @@ -120,28 +120,7 @@ sub _search_packages { ? $_ : @{[]}; } $urpm->packages_providing($v)) { - #- find the lowest value of is_arch_compat - my ($noarch, $arch) = partition { $_->arch eq 'noarch' } @l; - my %compats; - push @{$compats{$_->is_arch_compat}}, $_ foreach @$arch; - - delete $compats{0}; #- means not compatible - #- if there are pkgs matching arch, prefer them - if (%compats && !$options{all}) { - my $best_arch = min(keys %compats); - %compats = ($best_arch => $compats{$best_arch}); - } - if (%compats) { - @l = (@$noarch, map { @$_ } values %compats); - } - - #- we assume that if there is at least one package providing - #- the resource exactly, this should be the best one; but we - #- first check if one of the packages has the same name as searched. - if (my @l2 = grep { $_->name eq $v } @l) { - @l = @l2; - } - $exact{$v} = join('|', map { $_->id } @l); + $exact{$v} = _search_packages_keep_best($v, \@l, $options{all}); next; } } elsif ($options{use_provides}) { @@ -216,6 +195,32 @@ sub _search_packages { \%name2ids, $result; } +#- side-effects: none +sub _search_packages_keep_best { + my ($name, $pkgs, $all) = @_; + + #- find the lowest value of is_arch_compat + my ($noarch, $arch) = partition { $_->arch eq 'noarch' } @$pkgs; + my %compats; + push @{$compats{$_->is_arch_compat}}, $_ foreach @$arch; + + delete $compats{0}; #- means not compatible + #- if there are pkgs matching arch, prefer them + if (%compats && !$all) { + my $best_arch = min(keys %compats); + %compats = ($best_arch => $compats{$best_arch}); + } + my @l = %compats ? (@$noarch, map { @$_ } values %compats) : @$pkgs; + + #- we assume that if there is at least one package providing + #- the resource exactly, this should be the best one; but we + #- first check if one of the packages has the same name as searched. + if (my @l2 = grep { $_->name eq $name } @l) { + @l = @l2; + } + join('|', map { $_->id } @l); +} + #- Resolves dependencies between requested packages (and auto selection if any). #- handles parallel option if any. #- The return value is true if program should be restarted (in order to take -- cgit v1.2.1