[lintian] 01/03: L::Unpacker: Correct error handling of L::L::Entry->create
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit fcd47235708ee130c6d1cd209b09c9a3e18030ae
Author: Niels Thykier <niels@thykier.net>
Date: Fri Dec 30 20:48:53 2016 +0000
L::Unpacker: Correct error handling of L::L::Entry->create
The L::L::Entry->create will throw an exception on errors and not
return a false value. At the same time, optimise the call so we can
save an explicit call to L::L::Entry->exists first (saving 2 stat
calls per package).
Signed-off-by: Niels Thykier <niels@thykier.net>
---
lib/Lintian/Lab/Entry.pm | 6 +++---
lib/Lintian/Unpacker.pm | 17 +++++------------
2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/lib/Lintian/Lab/Entry.pm b/lib/Lintian/Lab/Entry.pm
index b53da69..1061ae0 100644
--- a/lib/Lintian/Lab/Entry.pm
+++ b/lib/Lintian/Lab/Entry.pm
@@ -31,8 +31,8 @@ Lintian::Lab::Entry - A package inside the Lab
my $lab = Lintian::Lab->new ("dir");
my $lpkg = $lab->get_package ("name", "type", "version", "arch");
- # create the entry if it does not exist
- $lpkg->create unless $lpkg->exists;
+ # create the entry
+ $lpkg->create;
# obtain a Lintian::Collect object.
my $info = $lpkg->info;
@@ -279,7 +279,7 @@ sub create {
# If $base_dir exists, then check if the entry exists
# - this is optimising for "non-existence" which is
# often the common case.
- return 1 if $self->exists;
+ return 0 if $self->exists;
}
if ($pkg_type eq 'changes'){
$link = "$base_dir/changes";
diff --git a/lib/Lintian/Unpacker.pm b/lib/Lintian/Unpacker.pm
index 9a9ae43..ea9d1c8 100644
--- a/lib/Lintian/Unpacker.pm
+++ b/lib/Lintian/Unpacker.pm
@@ -212,15 +212,11 @@ sub prepare_tasks {
my ($self, $errorhandler, @lpkgs) = @_;
my %worklists;
foreach my $lpkg (@lpkgs) {
- my $changed = 0;
- my $cmap;
- my $needed;
-
- if ($lpkg->exists) {
- # It already exists, do nothing.
- 1;
- } elsif (not $lpkg->create){
- eval {$errorhandler->($lpkg);};
+ my ($changed, $cmap, $needed);
+
+ eval {$changed = $lpkg->create;};
+ if (my $e = $@) {
+ eval {$errorhandler->($lpkg, $e);};
if ($@) {
# The error handler croaked; attempt to write status
# files for entries we created.
@@ -236,9 +232,6 @@ sub prepare_tasks {
die $err;
}
next;
- } else {
- # created
- $changed = 1;
}
($cmap, $needed) = $self->_requested_colls($lpkg, $changed);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: