[lintian] 07/08: L::Lab: Automatically fix "out-of-sync" metadata when discovered
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit c50e8e192a655ca4bf414500abcf5ada4a8d2f8a
Author: Niels Thykier <niels@thykier.net>
Date: Sun Feb 22 15:47:23 2015 +0100
L::Lab: Automatically fix "out-of-sync" metadata when discovered
When a client requests an entry, correct the metadata if it believes
the entry to exist and L::Lab::Entry disagrees. This automatically
solves the most common type of "lab corruption" over time as entries
are revisited.
Signed-off-by: Niels Thykier <niels@thykier.net>
---
debian/changelog | 5 +++++
lib/Lintian/Lab.pm | 32 +++++++++++++++++++-------------
lib/Lintian/Lab/Entry.pm | 12 ++++++++++--
3 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index ce2a737..0caf0a0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -118,6 +118,11 @@ lintian (2.5.31) UNRELEASED; urgency=medium
+ [NT] Null fields extra metadata fields in the lab storage
that are no longer used. These were previously used by
the reporting framework.
+ + [NT] Automatically correct lab metadata, when the lab
+ discovers an entry does not exist. Any remains of the
+ entry will be removed as well. Previously, the lab would
+ just throw an error and require a manuel correction of
+ the lab.
* lib/Lintian/Util.pm:
+ [NT] Prefer dpkg-deb --ctrl-tarfile to "ar p" when dpkg
is recent enough.
diff --git a/lib/Lintian/Lab.pm b/lib/Lintian/Lab.pm
index 99e94fb..f55e10a 100644
--- a/lib/Lintian/Lab.pm
+++ b/lib/Lintian/Lab.pm
@@ -296,9 +296,7 @@ sub get_package {
$pkg_src = $entry->{'source'};
$dir = $self->_pool_path($pkg_src, $pkg_type, $pkg_name, $pkg_version,
$pkg_arch);
- push @entries,
- Lintian::Lab::Entry->new_from_metadata($pkg_type, $entry, $self,
- $dir);
+ push(@entries, _entry_from_metadata($pkg_type, $entry, $self,$dir));
} else {
# clear $pkg_arch if it is a source package - it simplifies
# the search code below
@@ -313,9 +311,7 @@ sub get_package {
$dir
= $self->_pool_path($entry->{'source'}, $pkg_type, $pkg_name,$v,
$a);
- push @entries,
- Lintian::Lab::Entry->new_from_metadata($pkg_type, $entry, $self,
- $dir);
+ push(@entries,_entry_from_metadata($pkg_type, $entry, $self,$dir));
};
my @sk = ($pkg_name);
push @sk, $pkg_version if defined $pkg_version;
@@ -417,9 +413,8 @@ sub lab_query {
= $self->_pool_path($entry->{'source'}, $entry_type,
$entry->{'package'}, $entry->{'version'},
$entry->{'architecture'});
- push @result,
- Lintian::Lab::Entry->new_from_metadata($entry_type, $entry,
- $self, $dir);
+ push(@result,
+ _entry_from_metadata($entry_type, $entry, $self, $dir));
};
push @keys, $version if defined $version;
$index->visit_all($searcher, @keys);
@@ -451,10 +446,10 @@ sub visit_packages {
my $dir
= $self->_pool_path($pkg_src, $pkg_type, $pkg_name, $pkg_version,
$pkg_arch);
- my $lentry
- = Lintian::Lab::Entry->new_from_metadata($pkg_type, $me, $self,
- $dir);
- $visitor->($lentry, $pkg_name, $pkg_version, $pkg_arch);
+ my $lentry= _entry_from_metadata($pkg_type, $me, $self,$dir);
+ if ($lentry) {
+ $visitor->($lentry, $pkg_name, $pkg_version, $pkg_arch);
+ }
};
$index->visit_all($intv);
}
@@ -936,6 +931,17 @@ sub is_temp {
return $self->{'mode'} eq LAB_MODE_TEMP ? 1 : 0;
}
+sub _entry_from_metadata {
+ my (@args) = @_;
+ my $entry;
+ eval {$entry = Lintian::Lab::Entry->new_from_metadata(@args);};
+ if (my $err = $@) {
+ die($err) if $err ne "entry-disappeared\n";
+ return;
+ }
+ return $entry;
+}
+
# event - triggered by Lintian::Lab::Entry
sub _entry_removed {
my ($self, $entry) = @_;
diff --git a/lib/Lintian/Lab/Entry.pm b/lib/Lintian/Lab/Entry.pm
index 6a889d4..8425f83 100644
--- a/lib/Lintian/Lab/Entry.pm
+++ b/lib/Lintian/Lab/Entry.pm
@@ -437,9 +437,17 @@ sub _init {
# This error should not happen unless someone (read: me) breaks
# Lintian::Lab::get_package
my $pkg_type = $self->pkg_type;
- my $id = $self->identifier;
- croak "$id does not exists" unless $exists;
my $link;
+ if (not $exists) {
+ # This happens with the metadata gets out of sync with reality.
+ # (e.g. unclean close). Solve it by purging the entry.
+ $self->remove;
+ # Ensure the lab knows the entry us gone. Depending on how
+ # "missing" the entry is, remove might fail to do it for us.
+ $self->{'lab'}->_entry_removed($self);
+ # Use die as croak insists on adding " at <...>"
+ die("entry-disappeared\n");
+ }
$link = 'deb' if $pkg_type eq 'binary' or $pkg_type eq 'udeb';
$link = 'dsc' if $pkg_type eq 'source';
$link = 'changes' if $pkg_type eq 'changes';
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: