[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.12-38-gcf5a863



The following commit has been merged in the master branch:
commit cf5a863e297fc5ee2c081e04d3142b18acce2103
Author: Niels Thykier <niels@thykier.net>
Date:   Wed Apr 24 09:20:40 2013 +0200

    lib+t: Convert a couple of modules to use autodie
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 2af66e4..cd74359 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -22,6 +22,7 @@ package Lintian::Collect::Binary;
 
 use strict;
 use warnings;
+use autodie;
 use parent 'Lintian::Collect::Package';
 
 use Lintian::Relation;
@@ -246,8 +247,7 @@ sub md5sums {
     my $result = {};
 
     # read in md5sums info file
-    open my $fd, '<', $md5f
-        or fail "cannot open $md5f info file: $!";
+    open(my $fd, '<', $md5f);
     while (my $line = <$fd>) {
         chop($line);
         next if $line =~ m/^\s*$/o;
@@ -306,8 +306,7 @@ sub scripts {
     my $scrf = $self->lab_data_path ('scripts');
     my %scripts;
     local $_;
-    open my $fd, '<', $scrf
-        or fail "cannot open scripts $scrf: $!";
+    open(my $fd, '<', $scrf);
     while ( my $line = <$fd> ) {
         my (%file, $name);
         chomp ($line);
@@ -321,7 +320,7 @@ sub scripts {
         $file{name} = $name;
         $scripts{$name} = \%file;
     }
-    close $fd;
+    close($fd);
     $self->{scripts} = \%scripts;
 
     return $self->{scripts};
@@ -402,7 +401,7 @@ sub objdump_info {
     }
     $self->{objdump_info} = \%objdump_info;
 
-    close $fd;
+    close($fd);
 
     return $self->{objdump_info};
 }
@@ -425,8 +424,7 @@ sub hardening_info {
     my %hardening_info;
     my ($file);
     local $_;
-    open my $idx, '<', $hardf
-        or fail "cannot open $hardf: $!";
+    open(my $idx, '<', $hardf);
     while (<$idx>) {
         chomp;
 
@@ -437,7 +435,7 @@ sub hardening_info {
     }
 
     $self->{hardening_info} = \%hardening_info;
-
+    close($idx);
     return $self->{hardening_info};
 }
 
@@ -527,6 +525,7 @@ sub java_info {
         }
     }
     $self->{java_info} = \%java_info;
+    close($idx);
     return $self->{java_info};
 }
 
@@ -663,7 +662,7 @@ sub is_conffile {
     # No real packages use links in their control.tar.gz and conffiles
     # must be a file.
     return if -l $cf or not -f $cf;
-    open my $fd, '<', $cf or fail "opening control/conffiles: $!";
+    open(my $fd, '<', $cf);
     while ( my $line = <$fd> ) {
         chomp $line;
         next if $line =~ m/^\s*$/;
@@ -673,7 +672,7 @@ sub is_conffile {
         $line =~ s,^/++,,o;
         $conffiles{$line} = 1;
     }
-    close $fd;
+    close($fd);
     return 1 if exists $conffiles{$file};
     return;
 }
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index cc5bab2..fbabc39 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -21,6 +21,8 @@ package Lintian::Collect::Package;
 
 use strict;
 use warnings;
+use autodie;
+
 use parent 'Lintian::Collect';
 
 use Carp qw(croak);
@@ -35,15 +37,17 @@ Lintian::Collect::Package - Lintian base interface to binary and source package
 
 =head1 SYNOPSIS
 
+    use autodie;
+    use Lintian::Collect;
+    
     my ($name, $type, $dir) = ('foobar', 'source', '/path/to/lab-entry');
     my $info = Lintian::Collect->new ($name, $type, $dir);
     my $filename = "etc/conf.d/$name.conf";
     my $file = $info->index($filename);
     if ($file && $file->is_regular_file) {
-        open my $fd, '<', $info->unpacked($file)
-            or die "opening $filename: $!";
+        open(my $fd, '<', $info->unpacked($file));
         # Use $fd ...
-        close $fd;
+        close($fd);
     } elsif ($file) {
         print "$file is available, but not a regular file\n";
     } else {
@@ -169,7 +173,7 @@ sub file_info {
 
         $file_info{$file} = $info;
     }
-    close $idx;
+    close($idx);
     $self->{file_info} = \%file_info;
 
     return $self->{file_info}->{$file}
@@ -420,8 +424,8 @@ sub _fetch_index_data {
     # Remove the "top" dir in the sorted_index as it is hardly ever used.
     shift @sorted if scalar @sorted && $sorted[0] eq '';
     $self->{"sorted_$field"} = \@sorted;
-    close $idx;
-    close $num_idx if $num_idx;
+    close($idx);
+    close($num_idx) if $num_idx;
     return $self->{$field}->{$file} if exists $self->{$field}->{$file};
     return;
 }
diff --git a/lib/Lintian/Data.pm b/lib/Lintian/Data.pm
index 610e4d1..021ba8a 100644
--- a/lib/Lintian/Data.pm
+++ b/lib/Lintian/Data.pm
@@ -17,8 +17,10 @@
 # this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package Lintian::Data;
+
 use strict;
 use warnings;
+use autodie;
 
 use Carp qw(croak);
 
@@ -66,7 +68,7 @@ sub new {
             my ($fd, $vno) = $self->_open_data_file ($type, $vendors, 0);
             $self->_parse_file ($type, $fd, $dataset, $separator, $code,
                                 $vendors, $vno);
-            close $fd;
+            close($fd);
             $data{$type} = $dataset;
         }
         $self->{'data'} = $data{$type};
@@ -123,8 +125,7 @@ sub new {
             croak "Unknown data file: $type" unless $start;
             croak "No parent data file for $vendors->[$start]";
         }
-        open my $fd, '<', "$file"
-            or croak "$file: $!";
+        open(my $fd, '<', "$file");
         return ($fd, $cur);
     }
 }
@@ -148,7 +149,7 @@ sub _parse_file {
                                                           $vno +1);
                 $self->_parse_file ($type, $pfd, $dataset, $separator,
                                     $code, $vendors, $pvo);
-                close $pfd;
+                close($pfd);
             } else {
                 croak "Unknown operation \@$op in $filename at line $.";
             }
diff --git a/lib/Lintian/Lab/Manifest.pm b/lib/Lintian/Lab/Manifest.pm
index 3900adb..9a54294 100644
--- a/lib/Lintian/Lab/Manifest.pm
+++ b/lib/Lintian/Lab/Manifest.pm
@@ -22,6 +22,7 @@ package Lintian::Lab::Manifest;
 
 use strict;
 use warnings;
+use autodie;
 
 use parent qw(Class::Accessor Clone);
 
@@ -251,7 +252,7 @@ sub write_list {
     my $visitor;
 
 
-    open my $fd, '>', $file or croak "open $file: $!";
+    open(my $fd, '>', $file);
     print $fd "$header\n";
 
     $visitor = sub {
@@ -263,7 +264,7 @@ sub write_list {
 
     $self->visit_all ($visitor);
 
-    close $fd or croak "close $file: $!";
+    close($fd);
     $self->_mark_dirty(0);
     return 1;
 }
@@ -526,10 +527,13 @@ sub _do_read_file {
     my ($self, $file, $header, $fields, $qf) = @_;
     my $count = scalar @$fields;
     my $root = {};
-    open my $fd, '<', $file or croak "open $file: $!";
+    open(my $fd, '<', $file);
     my $hd = <$fd>;
     chop $hd;
     unless ($hd eq $header) {
+        # The interesting part here is the format is invalid, so
+        # "ignore" errors from close
+        no autodie qw(close);
         close($fd);
         croak "Unknown/unsupported file format ($hd)";
     }
@@ -540,7 +544,10 @@ sub _do_read_file {
         my (@values) = split m/\;/o, $line, $count;
         my $entry = {};
         unless ($count == scalar @values) {
-            close $fd;
+            # The interesting part here is the format is invalid, so
+            # "ignore" errors from close
+            no autodie qw(close);
+            close($fd);
             croak "Invalid line in $file at line $. ($_)"
         }
         for ( my $i = 0 ; $i < $count ; $i++) {
@@ -549,7 +556,7 @@ sub _do_read_file {
         $self->_make_alias_fields ($entry);
         $self->_do_set ($root, $qf, $entry);
     }
-    close $fd;
+    close($fd);
     return $root;
 }
 
diff --git a/lib/Lintian/Tags.pm b/lib/Lintian/Tags.pm
index db8738a..255a66f 100644
--- a/lib/Lintian/Tags.pm
+++ b/lib/Lintian/Tags.pm
@@ -21,6 +21,7 @@ package Lintian::Tags;
 
 use strict;
 use warnings;
+use autodie;
 
 use Exporter qw(import);
 use List::MoreUtils qw(any);
@@ -503,8 +504,7 @@ sub file_overrides {
     my $info = $self->{info}{$self->{current}};
     my $comments = [];
     my $last_over = undef;
-    open(my $file, '<', $overrides)
-        or fail("cannot open override file $overrides: $!");
+    open(my $file, '<', $overrides);
     local $_;
   OVERRIDE:
     while (<$file>) {
@@ -635,7 +635,7 @@ sub file_overrides {
             tag 'malformed-override', "Cannot parse line $.: $_";
         }
     }
-    close $file;
+    close($file);
 }
 
 =item file_end()
diff --git a/t/scripts/Lintian/Util/dctrl-parser.t b/t/scripts/Lintian/Util/dctrl-parser.t
index 7dd5a5f..7f5eef4 100644
--- a/t/scripts/Lintian/Util/dctrl-parser.t
+++ b/t/scripts/Lintian/Util/dctrl-parser.t
@@ -2,6 +2,7 @@
 
 use strict;
 use warnings;
+use autodie;
 
 use Test::More;
 
@@ -38,11 +39,11 @@ plan tests => scalar keys %TESTS_BAD;
 foreach my $filename (sort keys %TESTS_BAD) {
     my $fail_regex = $TESTS_BAD{$filename};
     my $path = "$DATADIR/$filename";
-    open my $fd, '<', $path or die "open $path: $!";
+    open(my $fd, '<', $path);
     eval {
         visit_dpkg_paragraph (sub {}, $fd);
     };
-    close $fd;
+    close($fd);
     if (my $err = $@) {
         like ($err, $fail_regex, $filename);
     } else {

-- 
Debian package checker


Reply to: