summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-dev/attachments/20130208/a0c61144/attachment-0001.obj
blob: 17cfc7ba4a8dad99d3995e1c977d8d9decbf5061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
commit f2056220a3255557942a3916a0869701751f5e35
Author: Thierry Vignaud <thierry.vignaud@gmail.com>
Date:   Fri Feb 8 18:35:06 2013 +0100

    (install_logger) keep a separate counter for erasures
    
    only initialize $total_pkg:
    - when starting a new transaction
    - or on first erasure in transaction
    
    (_compute_pkg_total) kill it (no more needed)
    
    adjust testsuite accordingly

diff --git a/NEWS b/NEWS
index b1057d8..e8d3cf9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- keep a separate counter for erasures
+
 Version 7.17 - 5 February 2013, by Thierry Vignaud
 
 - fix counting for erasures
diff --git a/t/superuser--obsolete-and-conflict.t b/t/superuser--obsolete-and-conflict.t
index be3af8b..5284618 100644
--- a/t/superuser--obsolete-and-conflict.t
+++ b/t/superuser--obsolete-and-conflict.t
@@ -31,10 +31,10 @@ sub test1 {
 
     my $arch = urpm::cfg::get_arch();
     test_urpmi("b c", sprintf(<<'EOF', $arch, $arch));
-      1/3: c
-      2/3: b
+      1/2: c
+      2/2: b
 removing package a-1-1.%s
-      3/3: removing a-1-1.%s
+      1/1: removing a-1-1.%s
 EOF
     check_installed_and_remove('b', 'c');
 }
diff --git a/urpm/install.pm b/urpm/install.pm
index 9a3ec05..25b9611 100644
--- a/urpm/install.pm
+++ b/urpm/install.pm
@@ -91,29 +91,33 @@ Standard logger for transactions
 =cut
 
 # install logger callback
-my ($erase_logger, $index);
+my ($erase_logger, $index, $total_pkg, $uninst_count);
 sub install_logger {
     my ($urpm, $type, undef, $subtype, $amount, $total) = @_;
-    my $total_pkg = $urpm->{nb_install};
     local $| = 1;
 
     if ($subtype eq 'start') {
 	$urpm->{logger_progress} = 0;
 	if ($type eq 'trans') {
+	    $total_pkg = $urpm->{nb_install};
 	    $urpm->{logger_count} ||= 0;
+	    $uninst_count = 0;
 	    my $p = N("Preparing...");
 	    print $p, " " x (33 - length $p);
 	} else {
 	    my $pname;
+	    my $cnt;
 	    if ($type eq 'uninst') {
+		$total_pkg = $urpm->{trans}->NElements - $index if !$uninst_count;
+		$cnt = ++$uninst_count;
 		$pname = N("removing %s", $urpm->{trans}->Element_fullname($index));
 		$erase_logger->($urpm, undef, undef, $subtype);
 	    } else {
 		# index already got bumped in {callback_open}:
 		$pname = $urpm->{trans}->Element_name($index-1);
+		++$urpm->{logger_count} if $pname;
+		$cnt = $pname ? $urpm->{logger_count} : '-';
 	    }
-	    ++$urpm->{logger_count} if $pname;
-	    my $cnt = $pname ? $urpm->{logger_count} : '-';
 	    my $s = sprintf("%9s: %-22s", $cnt . "/" . $total_pkg, $pname);
 	    print $s;
 	    $s =~ / $/ or printf "\n%9s  %-22s", '', '';
diff --git a/urpm/main_loop.pm b/urpm/main_loop.pm
index 5729035..ce1ea97 100644
--- a/urpm/main_loop.pm
+++ b/urpm/main_loop.pm
@@ -29,7 +29,7 @@ use urpm::select;
 use urpm::orphans;
 use urpm::get_pkgs;
 use urpm::signature;
-use urpm::util qw(any difference2 find intersection member partition untaint);
+use urpm::util qw(difference2 find intersection member partition untaint);
 
 #- global boolean options
 my ($auto_select, $no_install, $install_src, $clean, $noclean, $force, $parallel, $test);
@@ -309,32 +309,6 @@ sub _run_transaction {
     !$fatal;
 }
 
-# computes the number of packages to install or to erase -
-# side-effects: urpm->{nb_install}
-my $fullname2name_re = qr/^(.*)-[^\-]*-[^\-]*\.[^\.\-]*$/;
-sub _compute_pkg_total {
-    my ($urpm, $state, $options) = @_;
-    $urpm->{nb_install} = 0;
-
-    # first account for install/erasures we will schedule (upgrades count twice as they involve erasure of the older package):
-    foreach my $set (@{$state->{transaction} || []}) {
-	my ($install, $upgrade) = partition {
-	    my $pkg = $urpm->{depslist}[$_];
-	    $pkg && !$pkg->flag_installed;
-	} @{$set->{upgrade}};
-	my $remove = $options->{'allow-force'} ? [] : $set->{remove} || [];
-	my ($rm_count, $inst_count, $up_count) = (scalar(@$remove), scalar(values @$install), scalar(keys @$upgrade));
-	$urpm->{nb_install} += $rm_count + $inst_count + 2 * $up_count;
-    }
-
-    # account for erases added by rpm (removal through obsoletes):
-    foreach my $fn (keys %{$state->{transaction_state}{rejected} || {}}) {
-	my ($n) = $fn =~ $fullname2name_re;
-	next if !keys %{$state->{transaction_state}{rejected}{$fn}{obsoleted}};
-	$urpm->{nb_install}++ if any { !/^\Q$n/ } keys %{$state->{transaction_state}{rejected}{$fn}{obsoleted}};
-    }
-}
-
 =item run($urpm, $state, $something_was_to_be_done, $ask_unselect, $_requested, $callbacks)
 
 Run the main urpm loop:
@@ -425,9 +399,6 @@ sub run {
     my $migrate_back_rpmdb_db_version = 
       $urpm->{root} && urpm::select::should_we_migrate_back_rpmdb_db_version($urpm, $state);
 
-    #- compute package total:
-    _compute_pkg_total($urpm, $state, $options);
-
     #- now process each remove/install transaction
     foreach my $set (@{$state->{transaction} || []}) {