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

[SCM] Debian package checker branch, master, updated. 2.5.11-224-g7639dee



The following commit has been merged in the master branch:
commit 7639dee9e25cf3c464dbf22a0bdbcf4ca645c5b1
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Apr 4 14:42:17 2013 +0200

    Use autodie for {open,close}dir and replace bareword handles
    
    Ensure errors from opendir/closedir is always trapped.  For files,
    where critic found a violation (only found closedir-cases) convert
    them to autodie.  At the same time, convert bareword dir handles into
    lexical ones.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/.perlcriticrc b/.perlcriticrc
index a404eff..ca535e1 100644
--- a/.perlcriticrc
+++ b/.perlcriticrc
@@ -29,7 +29,7 @@ allow-unsafe = 1
 [BuiltinFunctions::ProhibitBooleanGrep]
 
 [InputOutput::RequireCheckedSyscalls]
-functions = open opendir chdir
+functions = open opendir chdir read readline closedir sysopen sysread sysclose
 # possible TODO read readline readdir close closedir
 
 # Checks and collections blow up
diff --git a/checks/debhelper b/checks/debhelper
index 841d3f1..6b52d91 100644
--- a/checks/debhelper
+++ b/checks/debhelper
@@ -21,6 +21,7 @@
 package Lintian::debhelper;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Lintian::Data;
 use Lintian::Relation;
@@ -285,9 +286,8 @@ if ($seendhcleank and $level >= 7) {
 # Check the files in the debian directory for various debhelper-related
 # things.
 my @indebfiles = ();
-opendir(DEBIAN, $droot)
-    or fail("Can't open debfiles directory.");
-foreach my $file (sort readdir(DEBIAN)) {
+opendir(my $dirfd, $droot);
+for my $file (sort(readdir($dirfd))) {
     next if $file eq 'rules' or not -f "$droot/$file";
     if ($file =~ m/^(?:(.*)\.)?(?:post|pre)(?:inst|rm)$/) {
         next unless $needtomodifyscripts;
@@ -374,7 +374,7 @@ foreach my $file (sort readdir(DEBIAN)) {
         }
     }
 }
-closedir(DEBIAN);
+closedir($dirfd);
 
 $bdepends_noarch = $info->relation_noarch('build-depends-all');
 $bdepends = $info->relation('build-depends-all');
diff --git a/checks/init.d b/checks/init.d
index a14a715..2c139ef 100644
--- a/checks/init.d
+++ b/checks/init.d
@@ -21,6 +21,7 @@
 package Lintian::init_d;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use List::MoreUtils qw(any none);
 
@@ -182,9 +183,8 @@ foreach my $initd_file (keys %initd_postinst) {
 }
 
 # files actually installed in /etc/init.d should match our list :-)
-opendir INITD, $initd_dir
-    or fail "cannot read init.d directory: $!";
-for my $script (readdir(INITD)) {
+opendir(my $dirfd, $initd_dir);
+for my $script (readdir($dirfd)) {
     my $tagname = 'script-in-etc-init.d-not-registered-via-update-rc.d';
     next if any {$script eq $_} qw(. .. README skeleton rc rcS);
 
@@ -208,7 +208,7 @@ for my $script (readdir(INITD)) {
         check_init ($script, $script_path) if -f $script_path;
     }
 }
-closedir(INITD);
+closedir($dirfd);
 
 }
 
diff --git a/checks/menu-format b/checks/menu-format
index 1849236..651f091 100644
--- a/checks/menu-format
+++ b/checks/menu-format
@@ -35,6 +35,7 @@
 package Lintian::menu_format;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use File::Basename;
 use List::MoreUtils qw(any);
@@ -211,12 +212,11 @@ my ($pkg, $type, $info, $proc, $group) = @_;
 
 my $mdir = $info->lab_data_path ('menu');
 my @menufiles;
-opendir MENUDIR, "$mdir/lib" or fail 'cannot read menu/lib file directory';
-push @menufiles, map { "$mdir/lib/$_" } readdir (MENUDIR);
-closedir MENUDIR;
-opendir MENUDIR, "$mdir/share" or fail 'cannot read menu/share file directory';
-push @menufiles, map { "$mdir/share/$_" } readdir (MENUDIR);
-closedir MENUDIR;
+for my $dir ("$mdir/lib", "$mdir/share") {
+    opendir(my $dirfd, $dir);
+    push(@menufiles, map { "$dir/$_" } readdir($dirfd));
+    close($dirfd);
+}
 
 # Find the desktop files in the package for verification.
 my @desktop_files;
diff --git a/checks/menus b/checks/menus
index c086519..52f5f0e 100644
--- a/checks/menus
+++ b/checks/menus
@@ -23,6 +23,7 @@
 package Lintian::menus;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Lintian::Check qw(check_spelling check_spelling_picky $known_shells_regex);
 use Lintian::Data;
@@ -183,17 +184,16 @@ if ($prerm{'calls-installdocs'} or $prerm{'calls-installdocs-r'}) {
 # check consistency
 # docbase file?
 if ($docbase_file) {
-    opendir DOCBASEDIR, $info->lab_data_path ('doc-base')
-        or fail 'cannot read doc-base directory';
+    opendir(my $dirfd, $info->lab_data_path('doc-base'));
     my $dbfile;
-    while (defined ($dbfile = readdir DOCBASEDIR)) {
+    while (defined($dbfile = readdir($dirfd)) ) {
         my $dbpath = $info->lab_data_path ("doc-base/$dbfile");
         # don't try to parse executables, plus we already warned about it
         next if -x $dbfile;
         check_doc_base_file ($dbfile, $dbpath, $pkg, $type, \%all_files, \%all_links,
                              $group);
     }
-    closedir DOCBASEDIR;
+    closedir($dirfd);
 } elsif ($documentation) {
     if ($pkg =~ /^libghc6?-.*-doc$/) {
         # This is the library documentation for a haskell library. Haskell
diff --git a/checks/po-debconf b/checks/po-debconf
index 4211006..8ade5c0 100644
--- a/checks/po-debconf
+++ b/checks/po-debconf
@@ -21,6 +21,7 @@
 package Lintian::po_debconf;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Lintian::Tags qw(tag);
 use Lintian::Util qw(fail system_env);
@@ -35,11 +36,11 @@ my $debfiles = $info->debfiles;
 # First, check wether this package seems to use debconf but not po-debconf.
 # Read the templates file and look at the template names it provides, since
 # some shared templates aren't translated.
-opendir(DEB, $debfiles)
-    or fail("Can't open debfiles directory.");
+opendir(my $dirfd, $debfiles);
+
 my $has_template = my $has_depends = my $has_config = 0;
 my @lang_templates;
-for my $file (readdir(DEB)) {
+for my $file (readdir($dirfd)) {
     next if -d "$debfiles/$file";
     if ($file =~ m/^(.+\.)?templates(\..+)?$/) {
         if ($file =~ m/templates\.\w\w(_\w\w)?$/) {
@@ -77,7 +78,7 @@ for my $file (readdir(DEB)) {
         }
     }
 }
-closedir(DEB);
+closedir($dirfd);
 
 #TODO: check whether all templates are named in TEMPLATES.pot
 if ( $has_template ) {
@@ -136,9 +137,8 @@ if (-x '/usr/bin/msgcmp' && -x '/usr/share/intltool-debian/intltool-update' ) {
 if (! -x '/usr/bin/msgfmt' ) {
     fail('msgfmt not found');
 }
-opendir(DEBIAN, "$debfiles/po")
-        or fail("Can't open debfiles/po directory.");
-while (defined(my $file=readdir(DEBIAN))) {
+opendir(my $po_dirfd, "$debfiles/po");
+while (defined(my $file=readdir($po_dirfd))) {
     next unless $file =~ m/\.po$/;
     tag 'misnamed-po-file', "debian/po/$file"
         unless ($file =~ /^[a-z]{2,3}(_[A-Z]{2})?(?:\@[^\.]+)?\.po$/o);
@@ -169,7 +169,7 @@ while (defined(my $file=readdir(DEBIAN))) {
         $full_translation = 1;
     }
 }
-closedir DEBIAN;
+closedir($po_dirfd);
 
 tag 'no-complete-debconf-translation' if !$full_translation;
 
diff --git a/collection/scripts b/collection/scripts
index 859b752..4646414 100755
--- a/collection/scripts
+++ b/collection/scripts
@@ -23,6 +23,7 @@ package Lintian::coll::scripts;
 
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use lib "$ENV{'LINTIAN_ROOT'}/lib/";
 use Lintian::Collect;
@@ -34,7 +35,6 @@ my $info = Lintian::Collect->new ($pkg, $type, $dir);
 
 open SCRIPTS, '>', "$dir/scripts" or fail "cannot open scripts output file: $!";
 
-my $file;
 my $magic;
 my $scriptpath;
 
@@ -72,10 +72,8 @@ close(SCRIPTS) or fail("cannot write scripts file: $!");
 open SCRIPTS, '>', "$dir/control-scripts"
     or fail("cannot open control-scripts output file: $!");
 
-opendir CONTROL, "$dir/control"
-    or fail("cannot read control directory: $!");
-
-for $file (readdir CONTROL) {
+opendir(my $dirfd, "$dir/control");
+for my $file (readdir($dirfd)) {
     next if -l "$dir/control/$file" or ! -f _;
     open FILE, '<', "$dir/control/$file" or fail "cannot open control/$file: $!";
     if (read(FILE, $magic, 2) and $magic eq '#!') {
@@ -85,7 +83,7 @@ for $file (readdir CONTROL) {
     }
     close(FILE);
 }
-closedir(CONTROL);
+closedir($dirfd);
 close(SCRIPTS) or fail("cannot write control-scripts file: $!");
 
 }
diff --git a/lib/Lintian/Internal/FrontendUtil.pm b/lib/Lintian/Internal/FrontendUtil.pm
index 84d5b96..4d91c2f 100644
--- a/lib/Lintian/Internal/FrontendUtil.pm
+++ b/lib/Lintian/Internal/FrontendUtil.pm
@@ -19,6 +19,7 @@
 package Lintian::Internal::FrontendUtil;
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Exporter qw(import);
 
@@ -49,8 +50,7 @@ sub check_test_feature{
 sub load_collections {
     my ($visitor, $dirname) = @_;
 
-    opendir my $dir, $dirname
-        or fail "cannot read directory $dirname: $!";
+    opendir(my $dir, $dirname);
 
     foreach my $file (readdir $dir) {
         next if $file =~ m/^\./;
@@ -59,7 +59,7 @@ sub load_collections {
         $visitor->($cs);
     }
 
-    closedir $dir;
+    closedir($dir);
 }
 
 # Return the default number of parallization to be used
diff --git a/lib/Lintian/Profile.pm b/lib/Lintian/Profile.pm
index a090557..c9945aa 100644
--- a/lib/Lintian/Profile.pm
+++ b/lib/Lintian/Profile.pm
@@ -23,6 +23,7 @@ use parent qw(Class::Accessor);
 
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Carp qw(croak);
 
@@ -553,14 +554,14 @@ sub _load_checks {
     my ($self) = @_;
     foreach my $checkdir ($self->include_path ('checks')) {
         next unless -d $checkdir;
-        opendir my $dirfd, $checkdir or croak "opendir $checkdir: $!";
+        opendir(my $dirfd, $checkdir);
         for my $desc (sort readdir $dirfd) {
             my $cname = $desc;
             next unless $cname =~ s/\.desc$//o;
             # _parse_check ignores duplicates, so we don't have to check for it.
             $self->_parse_check ($cname, $checkdir);
         }
-        closedir $dirfd;
+        closedir($dirfd);
     }
 }
 
diff --git a/private/tag-stats b/private/tag-stats
index 2666b15..ac71a3f 100755
--- a/private/tag-stats
+++ b/private/tag-stats
@@ -10,6 +10,7 @@
 
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 BEGIN {
     my $LINTIAN_ROOT = $ENV{'LINTIAN_ROOT'};
@@ -38,10 +39,8 @@ my $percent = 0;
 
 my $verbose = $ARGV[0] ? ($ARGV[0] =~ s/v/v/g) : 0;
 
-opendir(CHECKDIR, "$LINTIAN_ROOT/checks")
-    or fail("cannot read directory $LINTIAN_ROOT/checks");
-
-for my $check (readdir CHECKDIR) {
+opendir(my $checkdir, "$LINTIAN_ROOT/checks");
+for my $check (readdir($checkdir)) {
     next unless $check =~ /\.desc$/;
 
     my @tags = read_dpkg_control("$LINTIAN_ROOT/checks/$check");
@@ -78,7 +77,7 @@ for my $check (readdir CHECKDIR) {
     }
 }
 
-closedir(CHECKDIR);
+closedir($checkdir);
 
 print "Severity\n";
 foreach my $s (@severities) {
diff --git a/t/scripts/Lintian/Lab/repair.t b/t/scripts/Lintian/Lab/repair.t
index f7b73f9..14088ff 100755
--- a/t/scripts/Lintian/Lab/repair.t
+++ b/t/scripts/Lintian/Lab/repair.t
@@ -2,6 +2,7 @@
 
 use strict;
 use warnings;
+use autodie qw(opendir closedir);
 
 use Test::More;
 use Lintian::Lab;
@@ -57,7 +58,7 @@ sub do_tests {
 
     $empty_manifest = $LAB_A->_get_lab_index ('changes')->clone;
 
-    opendir my $dirfd, "$DATADIR/changes" or die "opendir $DATADIR/changes: $!";
+    opendir(my $dirfd, "$DATADIR/changes");
     foreach my $pkgbase (readdir $dirfd) {
         next unless $pkgbase =~ m/\.(?:changes|u?deb|dsc)$/;
         my $path = "$DATADIR/changes/$pkgbase";
@@ -66,7 +67,7 @@ sub do_tests {
         $entry->create;
         $added++;
     }
-    closedir $dirfd;
+    closedir($dirfd);
 
     $full_manifest = $LAB_A->_get_lab_index ('changes')->clone;
 

-- 
Debian package checker


Reply to: