[lintian] 03/03: L::Data: Avoid unnecessary stats of data files
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit a2eda653c31e041e41378253afb553b3566060f8
Author: Niels Thykier <niels@thykier.net>
Date: Fri Dec 30 21:25:17 2016 +0000
L::Data: Avoid unnecessary stats of data files
Signed-off-by: Niels Thykier <niels@thykier.net>
---
lib/Lintian/Data.pm | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/lib/Lintian/Data.pm b/lib/Lintian/Data.pm
index b79e709..d2367a0 100644
--- a/lib/Lintian/Data.pm
+++ b/lib/Lintian/Data.pm
@@ -23,11 +23,23 @@ use warnings;
use autodie;
use Carp qw(croak confess);
+use POSIX qw(ENOENT);
use Lintian::Util qw(strip);
our $LAZY_LOAD = 1;
+sub _checked_open {
+ my ($path) = @_;
+ my $fd;
+ eval {open($fd, '<', $path);};
+ if (my $err = $@) {
+ die($err) if not ref $err or $err->errno != ENOENT;
+ return;
+ }
+ return $fd;
+}
+
sub new {
my ($class, @args) = @_;
my $data_name = $args[0];
@@ -107,24 +119,24 @@ sub new {
# - $start is an index into $vendors (the first $vendor to try)
sub _open_data_file {
my ($self, $data_name, $vendors, $start) = @_;
- my $file;
+ my ($fd, $file);
my $cur = $start;
OUTER: for (; $cur < scalar @$vendors ; $cur++) {
my $vendorpart = "vendors/$vendors->[$cur]/data/$data_name";
foreach my $datafile ($profile->include_path($vendorpart)) {
- if (-f $datafile) {
- $file = $datafile;
- last OUTER;
- }
+ $fd =_checked_open($datafile);
+ next if not $fd;
+ $file = $datafile;
+ last OUTER;
}
}
if (not defined $file and $cur == scalar @$vendors) {
foreach my $datafile ($profile->include_path("data/$data_name")) {
- if (-f $datafile) {
- $file = $datafile;
- last;
- }
+ $fd =_checked_open($datafile);
+ next if not $fd;
+ $file = $datafile;
+ last;
}
$cur++;
}
@@ -132,7 +144,6 @@ sub new {
croak "Unknown data file: $data_name" unless $start;
croak "No parent data file for $vendors->[$start]";
}
- open(my $fd, '<', "$file");
return ($fd, $cur);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: