On Fri, 08 Jul 2011, Anders Kaseorg wrote:
> + my @field_names = qw(PackageSpec Version Status Conffiles Replaces);
> + local $/ = "\n\n";
> + open DPKG, '-|', 'dpkg-query', "--admindir=$DPKG",
> + '--showformat=' . (join '', map {"\${$_}$/"} @field_names),
> + '--show'
> + or die "$self: can't run dpkg-query ($!)\n";
PackageSpec is not supported in the current dpkg version so you can't
really use it until my branch gets merged and a new dpkg uploaded.
Or you should at least be able to deal with the case where it returns an
empty value.
And I don't really get the output format... why 2 \n after each field
value?
> - while (<STATUS>)
> + while (!eof DPKG)
> {
> - chomp;
> - my %field = map /^(\S+):\s+(.*)/ms, split /\n(?!\s)/;
> - next unless exists $field{Package}
> - and exists $field{Version}
> - and exists $field{Status}
> + my %field = map {$_, scalar <DPKG>} @field_names;
> + chomp @field{@field_names};
> + next unless $field{PackageSpec} ne ''
> + and $field{Version} ne ''
> and $field{Status} =~ /\sinstalled$/;
So you skip it if PackageSpec returns nothing.
> my $deb = $_;
> - my %field = map /^(\S+):\s+(.*)/ms, split /\n(?!\s)/,
> - `dpkg --field '$deb' Package Version Conffiles 2>/dev/null`;
> + my %field;
> + {
> + my @field_names = qw(PackageSpec Version Conffiles);
> + local $/ = "\n\n";
> + open DPKG, '-|', 'dpkg-deb',
> + '--showformat=' . (join '', map {"\${$_}$/"} @field_names),
> + '--show', $deb,
> + or die "$self: can't run dpkg-query ($!)\n";
> +
> + %field = map {$_, scalar <DPKG>} @field_names;
> + chomp @field{@field_names};
> +
> + close DPKG or die "$self: dpkg-deb failed (",
> + $! ? $! : $? >> 8 ? "exit status " . ($? >> 8) : "signal " . ($?
> & 127),
> + ")\n";
> + }
That's quite some code duplicated. It would probably be worth to factorize
the code.
The review is not complete because I think the first issue above is
already a blocker.
Cheers,
--
Raphaël Hertzog ◈ Debian Developer
Follow my Debian News ▶ http://RaphaelHertzog.com (English)
▶ http://RaphaelHertzog.fr (Français)
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]