Commit 271956b4 authored by Chris Lamb's avatar Chris Lamb 💬

Refactor, tidy and optimise various checks for the contents of files.

parent a950a964
...@@ -23,7 +23,7 @@ use strict; ...@@ -23,7 +23,7 @@ use strict;
use warnings; use warnings;
use autodie; use autodie;
use List::MoreUtils qw(any); use List::MoreUtils qw(none);
use Lintian::Data; use Lintian::Data;
use Lintian::Tags qw(tag); use Lintian::Tags qw(tag);
...@@ -191,8 +191,6 @@ my $BUILD_PATH_REGEX ...@@ -191,8 +191,6 @@ my $BUILD_PATH_REGEX
= Lintian::Data->new('files/build-path-regex',qr/~~~~~/, = Lintian::Data->new('files/build-path-regex',qr/~~~~~/,
sub { return qr/$_[0]/xsm;}); sub { return qr/$_[0]/xsm;});
my @ALLOWED_USES_DPKG_DATABASE = qw(base-files dpkg lintian);
sub _tag_build_tree_path { sub _tag_build_tree_path {
my ($path, $msg) = @_; my ($path, $msg) = @_;
foreach my $buildpath ($BUILD_PATH_REGEX->all) { foreach my $buildpath ($BUILD_PATH_REGEX->all) {
...@@ -347,8 +345,6 @@ sub run { ...@@ -347,8 +345,6 @@ sub run {
# Check if package is empty # Check if package is empty
my $is_dummy = $info->is_pkg_class('any-meta'); my $is_dummy = $info->is_pkg_class('any-meta');
my $has_sensible_utils = $info->relation('all')->implies('sensible-utils');
# read data from objdump-info file # read data from objdump-info file
foreach my $file (sort keys %{$info->objdump_info}) { foreach my $file (sort keys %{$info->objdump_info}) {
my $objdump = $info->objdump_info->{$file}; my $objdump = $info->objdump_info->{$file};
...@@ -1503,32 +1499,30 @@ sub run { ...@@ -1503,32 +1499,30 @@ sub run {
tag 'nfs-temporary-file-in-package', $file; tag 'nfs-temporary-file-in-package', $file;
} }
# ---------------- using sensible-utils w/o dependency # ---------------- contents checks
tag 'missing-depends-on-sensible-utils', $file my %checks
if not $has_sensible_utils = get_checks_for_file($info, $file, $source_pkg, $build_path);
and $fname !~ m,^usr/share/(?:doc|locale)/,
and $source_pkg ne 'lintian'
and detect_sensible_utils($file);
# ---------------- using dpkg internals if (%checks) {
if ($fname !~ m,^usr/share/(?:doc|locale)/,
and check_uses_dpkg($source_pkg, $pkg_section)) {
my $strings = slurp_entire_file($info->strings($file)); my $strings = slurp_entire_file($info->strings($file));
# If we have strings(1) output (eg. we are an ELF foreach my $tag (sort keys %checks) {
# binary) then prefer that. my $regex = $checks{$tag};
if ($strings) {
tag 'uses-dpkg-database-directly', $file # If we have strings(1) output (eg. we are an ELF
if $strings =~ m,^/var/lib/dpkg,m; # binary) then prefer that.
} else { if ($strings) {
my $fd = $file->open(':raw'); tag $tag, $file if $strings =~ m,^\Q$regex\E,m;
my $sfd = Lintian::SlidingWindow->new($fd); } else {
while (my $block = $sfd->readwindow) { my $fd = $file->open(':raw');
next unless $block =~ m,/var/lib/dpkg,; my $sfd = Lintian::SlidingWindow->new($fd);
tag 'uses-dpkg-database-directly', $file; while (my $block = $sfd->readwindow) {
last; next unless $block =~ $regex;
tag $tag, $file;
last;
}
close($fd);
} }
close($fd);
} }
} }
...@@ -2036,17 +2030,15 @@ sub run { ...@@ -2036,17 +2030,15 @@ sub run {
my $file = $info->control_index_resolved_path($1); my $file = $info->control_index_resolved_path($1);
next if not $file or not $file->is_open_ok; next if not $file or not $file->is_open_ok;
tag 'missing-depends-on-sensible-utils', $file my %checks
if not $has_sensible_utils and detect_sensible_utils($file); = get_checks_for_file($info, $file, $pkg_section, $build_path);
my $fd2 = $file->open;
if (check_uses_dpkg($source_pkg, $pkg_section)) { while (<$fd2>) {
my $fd2 = $file->open; foreach my $tag (sort keys %checks) {
while (<$fd2>) { tag $tag, $file, "(line $.)" if $_ =~ $checks{$tag};
tag 'uses-dpkg-database-directly', $file, "(line $.)"
if m,/var/lib/dpkg,;
} }
close($fd2);
} }
close($fd2);
} }
close($fd); close($fd);
...@@ -2349,27 +2341,24 @@ sub detect_privacy_breach { ...@@ -2349,27 +2341,24 @@ sub detect_privacy_breach {
return; return;
} }
sub detect_sensible_utils { sub get_checks_for_file {
my ($file) = @_; my ($info, $file, $source_pkg) = @_;
my $fd = $file->open(':raw'); my %checks;
my $sfd = Lintian::SlidingWindow->new($fd, sub { $_= lc($_); }, BLOCKSIZE);
while (my $block = $sfd->readwindow) { return %checks if $source_pkg eq 'lintian';
return 1
if $block=~ m/(?:select-editor|sensible-(?:browser|editor|pager))\b/;
}
close($fd);
return;
}
sub check_uses_dpkg { $checks{'missing-depends-on-sensible-utils'}
my ($source_pkg, $pkg_section) = @_; = '(?:select-editor|sensible-(?:browser|editor|pager))\b'
if $file !~ m,^usr/share/(?:doc|locale)/,
and not $info->relation('all')->implies('sensible-utils');
return 0 if $pkg_section eq 'debian-installer'; $checks{'uses-dpkg-database-directly'} = '/var/lib/dpkg'
return 0 if any { $_ eq $source_pkg } @ALLOWED_USES_DPKG_DATABASE; if $file !~ m,^usr/share/(?:doc|locale)/,
and $info->field('section', '') ne 'debian-installer'
and none { $_ eq $source_pkg } qw(base-files dpkg lintian);
return 1; return %checks;
} }
1; 1;
......
...@@ -11,6 +11,8 @@ lintian (2.5.117) UNRELEASED; urgency=medium ...@@ -11,6 +11,8 @@ lintian (2.5.117) UNRELEASED; urgency=medium
architecture-dependent package. This reverts 6f4bd2fee2 in order to architecture-dependent package. This reverts 6f4bd2fee2 in order to
distinguish between "data" and such scripts. Thanks to Dmitry distinguish between "data" and such scripts. Thanks to Dmitry
Bogatov for investigating. (Closes: #916023) Bogatov for investigating. (Closes: #916023)
+ [CL] Refactor, tidy and optimise various checks for the contents of
files.
* checks/watch-file.desc: * checks/watch-file.desc:
+ [CL] Correct grammar of the debian-watch-does-not-check-gpg-signature + [CL] Correct grammar of the debian-watch-does-not-check-gpg-signature
tag description. tag description.
......
E: files-missing-depends-on-sensible-utils: missing-depends-on-sensible-utils postinst E: files-missing-depends-on-sensible-utils: missing-depends-on-sensible-utils postinst (line 5)
E: files-missing-depends-on-sensible-utils: missing-depends-on-sensible-utils var/lib/test/test-script E: files-missing-depends-on-sensible-utils: missing-depends-on-sensible-utils var/lib/test/test-script
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment