pf-tools/pf-tools: add test to the result of close when using a ...

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Jul 31 15:51:51 UTC 2014


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/d28f09b3335a
changeset: 1294:d28f09b3335a
user:      shad
date:      Thu Jul 31 17:51:46 2014 +0200
description:
add test to the result of close when using a pipe otherwise we get too much error displayed

diffstat:

 lib/PFTools/Packages/DEB.pm |  45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diffs (145 lines):

diff -r a1f9fe7d9b35 -r d28f09b3335a lib/PFTools/Packages/DEB.pm
--- a/lib/PFTools/Packages/DEB.pm	Thu Jul 31 15:31:26 2014 +0200
+++ b/lib/PFTools/Packages/DEB.pm	Thu Jul 31 17:51:46 2014 +0200
@@ -56,7 +56,7 @@
 sub Pkg_status {
     my ($pkg_name) = @_;
 
-    return unless $pkg_name;
+    return if !$pkg_name;
 
     my $result = {};
     my $output_fh;
@@ -68,8 +68,10 @@
         return $result;
     }
 
-    unless ( $output_fh
-        = IO::File->new("$PKG_CMD->{'status'} '$pkg_name' 2>/dev/null |") )
+    if (!(  $output_fh
+            = IO::File->new("$PKG_CMD->{'status'} '$pkg_name' 2>/dev/null |")
+        )
+        )
     {
         carp qq{ERROR: while getting status for $pkg_name : $OS_ERROR}
             if ($VERBOSE);
@@ -89,7 +91,7 @@
             last;
         }
     }
-    unless ( $output_fh->close() ) {
+    if ( !$output_fh->close() ) {
         carp qq{ERROR: while closing pkg_status command : $OS_ERROR"}
             if ($VERBOSE);
         return;
@@ -109,7 +111,7 @@
 sub Pkg_purge {
     my ($pkg_name) = @_;
 
-    return unless $pkg_name;
+    return if !$pkg_name;
 
     if ( deferredlogsystem("$PKG_CMD->{'purge'} '$pkg_name'") ) {
         carp qq{ERROR: while purging $pkg_name : $OS_ERROR"}
@@ -122,12 +124,14 @@
 sub Pkg_depends {
     my ($pkg_name) = @_;
 
-    return unless $pkg_name;
+    return if !$pkg_name;
 
     my $dep_list = q{};
     my $output_fh;
-    unless ( $output_fh
-        = IO::File->new("$PKG_CMD->{'depends'} '$pkg_name' 2>/dev/null |") )
+    if (!(  $output_fh
+            = IO::File->new("$PKG_CMD->{'depends'} '$pkg_name' 2>/dev/null |")
+        )
+        )
     {
         carp qq{ERROR: while getting deps for $pkg_name : $OS_ERROR"}
             if ($VERBOSE);
@@ -135,23 +139,23 @@
     }
     while (<$output_fh>) {
         if (m{\A Depends: (.*) \z}xms) {
-            foreach my $pkg ( split( m{,}, $1 ) ) {
+            foreach my $pkg ( split m{,}, $1 ) {
                 if ( $pkg =~ m{|} ) {
                     $pkg =~ s{\([^\)]+\)}{}g;
                     $pkg =~ s{\s+}{}g;
-                    foreach my $possible_pkg ( split( m{|}, $pkg ) ) {
+                    foreach my $possible_pkg ( split m{|}, $pkg ) {
                         if ( $possible_pkg ne $pkg_name ) {
-                            $dep_list .= " " . $possible_pkg;
+                            $dep_list .= q{ } . $possible_pkg;
                         }
                     }
                 }
                 elsif ( $pkg ne $pkg_name ) {
-                    $dep_list .= " " . $pkg;
+                    $dep_list .= q{ } . $pkg;
                 }
             }
         }
     }
-    unless ( $output_fh->close() ) {
+    if ( !$output_fh->close() && !$CHILD_ERROR ) {
         carp qq{ERROR: while closing depends command : $OS_ERROR"}
             if ($VERBOSE);
         return;
@@ -166,13 +170,13 @@
 sub Pkg_policy {
     my ( $pkg_name, $version ) = @_;
 
-    return unless $pkg_name;
+    return if !$pkg_name;
     my ( $installed, $available, $specified_version, $output_fh );
 
     $specified_version = 0;
     $output_fh
         = IO::File->new("$PKG_CMD->{'policy'} '$pkg_name' 2>/dev/null |");
-    unless ($output_fh) {
+    if ( !$output_fh ) {
         carp qq{ERROR: while getting policy for $pkg_name : $OS_ERROR}
             if ($VERBOSE);
         return;
@@ -181,8 +185,9 @@
         chomp;
         if (m{\A  \s* Installed: \s* (.*) \z}xms) {
             $installed = $1;
-            undef $installed
-                if ( $installed eq '' or $installed eq "(none)" );
+            if ( $installed eq q{} or $installed eq q{(none)} ) {
+                undef $installed;
+            }
         }
         elsif (m{\A \s* Candidate: \s* (.*) \z}xms) {
             $available = $1;
@@ -191,7 +196,7 @@
             $specified_version = 1;
         }
     }
-    unless ( $output_fh->close() ) {
+    if ( !$output_fh->close() ) {
         carp qq{ERROR: while closing policy command : $OS_ERROR"}
             if ($VERBOSE);
         return;
@@ -202,7 +207,7 @@
 sub Pkg_compare_versions {
     my ( $pkg_name, $version1, $version2 ) = @_;
 
-    return unless $pkg_name or $version1 or $version2;
+    return if !$pkg_name && !$version1 && !$version2;
 
     if (!deferredlogsystem(
             "$PKG_CMD->{'compare'} '$version1' lt '$version2'"
@@ -227,7 +232,7 @@
 sub Pkg_install {
     my ( $pkg_name, $version ) = @_;
 
-    return unless $pkg_name;
+    return if !$pkg_name;
 
     my $install_cmd = $PKG_CMD->{'install'};
     $install_cmd .=



More information about the pf-tools-commits mailing list