From 0a4430109f3d1d3e757ec6d29b87fb74963ee2f2 Mon Sep 17 00:00:00 2001 From: Bill Allombert Date: Mon, 30 May 2011 20:42:12 +0000 Subject: [PATCH] popularity-contest: find package files lists by running dpkg -L by batches. --- debian/changelog | 7 ++++++ popularity-contest | 58 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/debian/changelog b/debian/changelog index 98f64bb..6775c3d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +popularity-contest (1.53) UNRELEASED; urgency=low + + * popularity-contest: + - find package files lists by running dpkg -L by batches. Closes: #622322 + + -- Bill Allombert Mon, 30 May 2011 17:04:20 +0200 + popularity-contest (1.52) unstable; urgency=low * Please note when reading stats that squeeze was released with 1.49. diff --git a/popularity-contest b/popularity-contest index 2375101..555ae0c 100755 --- a/popularity-contest +++ b/popularity-contest @@ -25,7 +25,7 @@ use strict; use 5.6.0; -my $dpkg_db="/var/lib/dpkg/info"; +my $dpkg_batch_size=32; #This is a time/space trade-off: higher = faster my $popcon_conf="/etc/popularity-contest.conf"; my %opts=(); @@ -92,23 +92,14 @@ if (opendir(PROC, "/proc")) } } -# Read dpkg database of installed packages -open PACKAGES, "dpkg-query --show --showformat='\${status} \${package}\\n'|"; -while () +#process the file list of a package +sub proc_pkg { - /^.*installed *(.+)$/ or next; - my $pkg=$1; + my ($pkg,@list)=@_; $popcon{$pkg}=[0,0,$pkg,""]; - open FILES, "$dpkg_db/$pkg.list" or - do { print STDERR "popcon: file $dpkg_db/$pkg.list is missing\n"; next; }; my $bestatime = undef; - while () + for (@list) { - chop; - next unless ( - ( m{/bin/|/sbin/|/lib/.+/|^/usr/games/|\.[ah]$|\.pm$|\.php$|^/boot/System\.map-} - || defined $mapped{$_} ) - && -f $_); my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat; @@ -138,9 +129,48 @@ while () } } } +} + +#process a list of packages. +sub proc_pkgs +{ + my (@pkgs)=@_; + open FILES, "-|", "dpkg -L @pkgs"; + my @list = (); + my $pkg = shift @pkgs; + while () + { + chop; + if ($_ eq "") + { + proc_pkg($pkg, @list); + $pkg = shift @pkgs; + @list = (); + } + next unless ( + ( m{/bin/|/sbin/|/lib/.+/|^/usr/games/|\.[ah]$|\.pm$|\.php$|^/boot/System\.map-} + || defined $mapped{$_} ) + && -f $_); + push @list, $_; + } + proc_pkg($pkg, @list); close FILES; } +# Read dpkg database of installed packages +open PACKAGES, "dpkg-query --show --showformat='\${status} \${package}\\n'|"; +my @pkglist = (); +while () +{ + /^.*installed *(.+)$/ or next; + push @pkglist, $1; + if (scalar @pkglist >= $dpkg_batch_size) + { + proc_pkgs(@pkglist); + @pkglist = (); + } +} +proc_pkgs(@pkglist) if (@pkglist); close PACKAGES; # We're not done yet. Sort the output in reverse by atime, and