summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2010-04-21 15:39:49 +0100
committerRichard Jones <rjones@redhat.com>2010-04-21 16:51:20 +0100
commit39416cdb11bb2005915ed293eafb3cc6d714416d (patch)
treebce3bac95ddbed883fd84d7d633476112635bc27
parent2b43970c8c97f24b1f45c040c6963d30661fa514 (diff)
downloadlibguestfs-39416cdb11bb2005915ed293eafb3cc6d714416d.tar.gz
libguestfs-39416cdb11bb2005915ed293eafb3cc6d714416d.tar.xz
libguestfs-39416cdb11bb2005915ed293eafb3cc6d714416d.zip
Don't die during inspection if rpm -qa or dpkg-query fails
If a problem in the package database prevented package enumeration from working, inspection would die. This change makes it emit a warning and continue.
-rw-r--r--perl/lib/Sys/Guestfs/Lib.pm28
1 files changed, 20 insertions, 8 deletions
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index b5b3906c..b6c4a31f 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -1463,10 +1463,16 @@ sub _check_for_applications
if ($osn eq "linux") {
my $package_format = $os->{package_format};
if (defined $package_format && $package_format eq "rpm") {
- my @lines = $g->command_lines
- (["rpm",
- "-q", "-a",
- "--qf", "%{name} %{epoch} %{version} %{release} %{arch}\n"]);
+ my @lines = ();
+ eval {
+ @lines = $g->command_lines
+ (["rpm",
+ "-q", "-a", "--qf",
+ "%{name} %{epoch} %{version} %{release} %{arch}\n"]);
+ };
+
+ warn(__x("Error running rpm -qa: {error}", error => $@)) if ($@);
+
@lines = sort @lines;
foreach (@lines) {
if (m/^(.*) (.*) (.*) (.*) (.*)$/) {
@@ -1483,10 +1489,16 @@ sub _check_for_applications
}
}
} elsif (defined $package_format && $package_format eq "deb") {
- my @lines = $g->command_lines
- (["dpkg-query",
- "-f", '${Package} ${Version} ${Architecture} ${Status}\n',
- "-W"]);
+ my @lines = ();
+ eval {
+ @lines = $g->command_lines
+ (["dpkg-query",
+ "-f", '${Package} ${Version} ${Architecture} ${Status}\n',
+ "-W"]);
+ };
+
+ warn(__x("Error running dpkg-query: {error}", error => $@)) if ($@);
+
@lines = sort @lines;
foreach (@lines) {
if (m/^(.*) (.*) (.*) (.*) (.*) (.*)$/) {