From 2e2c468fc4e77a62942d73702712bf68c1be3a1f Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Wed, 19 Oct 2005 17:01:42 +0000 Subject: Handle multi-valued tags --- urpmf | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'urpmf') diff --git a/urpmf b/urpmf index b1cc27ee..9a70b8f9 100755 --- a/urpmf +++ b/urpmf @@ -112,11 +112,25 @@ my $urpm = new urpm; $verbose or $urpm->{log} = sub {}; #- build the callback matching the expression. +#- count multi-valued tags +my $multi = 0; +my $multitag = ''; +my %multitags = map { $_ => 1 } qw/conffiles conflicts files obsoletes provides requires/; +while ($qf =~ /%[-\d]*(\w+)/g) { ++$multi, $multitag = $1 if $multitags{$1} } +$multi > 1 + and $urpm->{fatal}->(1, N("Incorrect format: you may use only one multi-valued tag")); + #- it would be nice to use "my $_" in this callback. -#- TODO handle multiple valued tags, requires, provides, files, etc my $callback = qq; + local *_;>; +if ($multi) { + $callback .= qq/ + for my \$mt (\$pkg->$multitag) {/; +} +$callback .= qq< + \$_ = sprintf(qq{$qf\\n}>; + my $sprintfargs = ''; while ($callback =~ /%[-\d]*(\w+)/g) { my $tag = $1; @@ -124,6 +138,8 @@ while ($callback =~ /%[-\d]*(\w+)/g) { $sprintfargs .= ', $urpm::currentmedia->{name}'; } elsif ($tag eq 'fullname') { $sprintfargs .= ', scalar($pkg->fullname)'; + } elsif ($tag eq $multitag) { + $sprintfargs .= ', $mt'; } else { $sprintfargs .= ', $pkg->' . $tag; } @@ -132,9 +148,9 @@ $callback =~ s/%([-\d]*)(\w+)/%${1}s/g; $uniq and $uniq = "\n" . ' $uniq{$_} and return 1; $uniq{$_} = 1;'; $callback .= qq<$sprintfargs); $expr or return 1;$uniq - print; - 1; -}>; + print;>; +$callback .= "\n }" if $multi; +$callback .= "\n 1;\n}"; $urpm->{error}("qf:[$qf]\ncallback:\n$callback") if our $debug; $callback = eval $callback; if ($@) { @@ -154,7 +170,7 @@ if ($env) { { #- lock to avoid concurrent media updates, #- but don't die if it doesn't work - local $urpm->{fatal} = sub { printf STDERR "%s\n", $_[0] }; + local $urpm->{fatal} = sub { printf STDERR "%s\n", $_[1] }; $urpm->shlock_urpmi_db; } my $use_hdlist = scalar grep { $params{$_} } qw( -- cgit v1.2.1