summaryrefslogtreecommitdiffstats
path: root/urpm/select.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-11-15 14:55:39 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-11-15 14:55:39 +0000
commit0129c9db2bc1f015b2cda5e209b65cc94fc902e0 (patch)
treebce1b108344bf2d672e8d6c58aa1d51579b4715b /urpm/select.pm
parentc44032fd6942be3fbcbffb18b3d2105bc3022023 (diff)
downloadurpmi-0129c9db2bc1f015b2cda5e209b65cc94fc902e0.tar
urpmi-0129c9db2bc1f015b2cda5e209b65cc94fc902e0.tar.gz
urpmi-0129c9db2bc1f015b2cda5e209b65cc94fc902e0.tar.bz2
urpmi-0129c9db2bc1f015b2cda5e209b65cc94fc902e0.tar.xz
urpmi-0129c9db2bc1f015b2cda5e209b65cc94fc902e0.zip
factorize some code by creating search_packages
Diffstat (limited to 'urpm/select.pm')
-rw-r--r--urpm/select.pm42
1 files changed, 26 insertions, 16 deletions
diff --git a/urpm/select.pm b/urpm/select.pm
index 14ae77fc..c8cf47a3 100644
--- a/urpm/select.pm
+++ b/urpm/select.pm
@@ -72,8 +72,27 @@ sub build_listid_ {
#- fuzzy
#- src
#- use_provides
+#-
+#- side-effects: $packages, flag_skip
sub search_packages {
my ($urpm, $packages, $names, %options) = @_;
+
+ my ($name2ids, $result) = _search_packages($urpm, $names, %options) or return;
+
+ foreach my $v (@$names) {
+ $packages->{$name2ids->{$v}} = 1;
+ foreach (split /\|/, $name2ids->{$v}) {
+ my $pkg = $urpm->{depslist}[$_] or next;
+ $urpm->{debug} and $urpm->{debug}("search_packages: found " . $pkg->fullname . " matching $v");
+ $pkg->set_flag_skip(0); #- reset skip flag as manually selected.
+ }
+ }
+ $result;
+}
+
+#- side-effects: none
+sub _search_packages {
+ my ($urpm, $names, %options) = @_;
my (%exact, %exact_a, %exact_ra, %found, %foundi);
foreach my $v (@$names) {
my $qv = quotemeta $v;
@@ -141,15 +160,10 @@ sub search_packages {
}
my $result = 1;
+ my %name2ids;
foreach my $v (@$names) {
- if (defined $exact{$v}) {
-
- $packages->{$exact{$v}} = 1;
- foreach (split /\|/, $exact{$v}) {
- my $pkg = $urpm->{depslist}[$_] or next;
- $urpm->{debug} and $urpm->{debug}("search_packages: found " . $pkg->fullname . " matching $v");
- $pkg->set_flag_skip(0); #- reset skip flag as manually selected.
- }
+ if (defined $exact{$v}) {
+ $name2ids{$v} = $exact{$v};
} else {
#- at this level, we need to search the best package given for a given name,
#- always prefer already found package.
@@ -164,7 +178,7 @@ sub search_packages {
N("The following packages contain %s: %s",
$v, "\n" . join("\n", sort { $a cmp $b } keys %l))
);
- $result = 0;
+ return;
} else {
if (!@{$exact_a{$v} || $exact_ra{$v} || []}) {
#- we found a non-exact match
@@ -180,18 +194,14 @@ sub search_packages {
}
}
my @l = grep { $_->fullname eq $best->fullname } @$_;
- $packages->{join('|', map { $_->id } @l)} = 1;
- foreach my $pkg (@l) {
- $urpm->{debug} and $urpm->{debug}("search_packages: found " . $pkg->fullname . " matching $v");
- $pkg->set_flag_skip(0); #- reset skip flag as manually selected.
- }
+ $name2ids{$v} = join('|', map { $_->id } @l);
}
}
}
}
- #- return true if no error has been encountered, else false.
- $result;
+ #- return 0 if error, 'substring' if fuzzy match, 1 if ok
+ \%name2ids, $result;
}
#- Resolves dependencies between requested packages (and auto selection if any).