Hi Manoj,
>> The postinst script of the package seems to generate policies for
>> all available packages, not only the installed ones,
>
> Why do you say that? The code seems to show that only
> installed packages have the corresponding policies loaded. The policy
> on my virtual machines seems different from the policy on my
> desktop.
I do not understand why you get different policies. Maybe your
/etc/apt/sources.list are different? To my knowledge,
system("dpkg-query -W $pkg > /dev/null 2>\&1") == 0
checks the exit status of dpkg-query. This is non-zero only for unknown
packages. If you test for a package that is not installed on your
system, say the package "wmcoincoin", you still get a non-zero exit.
=======================================================
#!/usr/bin/env perl
for my $pkg (@ARGV) {
print "checking $pkg:";
if( system("dpkg-query -W $pkg > /dev/null 2>\&1") == 0 ) {
print " non-zero exit status of 'dpkg-query -W $pkg'";
}
print "\n";
}
=======================================================
So, it is necessary to check the output of dpkg-query -W because only if
the package is installed, this contains a version number after the tab
character.
> This means going through every single installed package, even
> the ones we do not care specially for, as opposed to looking for
> packages corresponding to policy module packages.
Running the above script for ten package names:
real 0m18.824s
user 0m16.501s
sys 0m0.832s
Running the following script for ten package names:
real 0m1.774s
user 0m1.660s
sys 0m0.068s
=======================================================
#!/usr/bin/env perl
my %installed;
open( my $PACKAGES, "dpkg-query -W |" )
or die("Cannot run 'dpkg-query -W'. $!");
while( my $p = <$PACKAGES> ) {
$installed{$1} = $2 if( $p =~ /^(.*)\t(.+)$/ );
}
close($PACKAGES) or die("Could not close pipe.");
print "Listing only installed packages:\n";
foreach my $q (@ARGV) {
print "$q: $installed{$q}\n" if( $installed{$q} );
}
=======================================================
I think it is obvious that dpkg-query takes ~2s per invocation, so the
time gain is roughly (40-1)*1.8s=70s (assuming 40 avaiable policies)
just by calling dpkg-query only once. Of course the time for compiling
still adds to this.
Best wishes,
Alexander
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]