summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-08-20 16:29:23 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-08-20 16:29:23 +0000
commit89e7eee29e58c218e9546bf719590590b621485a (patch)
tree533866c1f75e1b18614048fb99e73679e02b93a9
parent153d33e90afb6608679804e9a8e79a6e9c0e2ba7 (diff)
downloadurpmi-89e7eee29e58c218e9546bf719590590b621485a.tar
urpmi-89e7eee29e58c218e9546bf719590590b621485a.tar.gz
urpmi-89e7eee29e58c218e9546bf719590590b621485a.tar.bz2
urpmi-89e7eee29e58c218e9546bf719590590b621485a.tar.xz
urpmi-89e7eee29e58c218e9546bf719590590b621485a.zip
create _search_packages_keep_best() out of _search_packages()
-rw-r--r--urpm/select.pm49
1 files 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