[devscripts] 02/02: dd-list: Use apt interfaces to access Sources files
James McCoy
jamessan at debian.org
Sun Jan 31 20:22:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
jamessan pushed a commit to branch master
in repository devscripts.
commit e14703c3f193f8e091430aaa2c542f328c52333a
Author: James McCoy <jamessan at debian.org>
Date: Sun Jan 31 15:22:09 2016 -0500
dd-list: Use apt interfaces to access Sources files
As described in <20160111171230.GA17291 at debian.org>, directly accessing
the files under /var/lib/apt/lists is error prone. APT provides
command-line interfaces to both determine the names of files and get
their contents, regardless of whether or how they're compressed.
Signed-off-by: James McCoy <jamessan at debian.org>
---
debian/changelog | 3 +++
scripts/dd-list.pl | 67 +++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 868cd21..164640c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -29,6 +29,9 @@ devscripts (2.16.1) UNRELEASED; urgency=medium
The specific commands aren't interesting, so much as the steps that the
build goes through. Fixes FTBFS due to new dh_update_autotools_config
command. (Closes: #812661)
+ * dd-list:
+ + Use apt interfaces to find sources files and extract their contents,
+ instead of globbing and directly reading files.
[ Christoph Berg ]
* debcheckout: Add auth mapping for https://github.com.
diff --git a/scripts/dd-list.pl b/scripts/dd-list.pl
index fb5721f..b450795 100755
--- a/scripts/dd-list.pl
+++ b/scripts/dd-list.pl
@@ -25,6 +25,7 @@ use warnings;
use FileHandle;
use Getopt::Long qw(:config gnu_getopt);
use Dpkg::Version;
+use Dpkg::IPC;
my $uncompress;
@@ -241,25 +242,69 @@ else {
$package_name{normalize_package($name)} = 1;
}
+ my $apt_version;
+ spawn(exec => ['dpkg-query', '-W', '-f', '${source:Version}', 'apt'],
+ to_string => \$apt_version,
+ wait_child => 1,
+ nocheck => 1);
+
+ my $useAptHelper = 0;
+ if (defined $apt_version)
+ {
+ $useAptHelper = version_compare_relation($apt_version, REL_GE, '1.1.8');
+ }
+
unless (@{$source_files}) {
- $source_files = [glob('/var/lib/apt/lists/*_source_Sources')];
+ if ($useAptHelper)
+ {
+ my ($sources, $err);
+ spawn(exec => ['apt-get', 'indextargets', '--format', '$(FILENAME)',
+ 'Created-By: Sources'],
+ to_string => \$sources,
+ error_to_string => \$err,
+ wait_child => 1,
+ nocheck => 1);
+ if ($? >> 8)
+ {
+ die "Unable to get list of Sources files from apt: $err\n";
+ }
+
+ $source_files = [split(/\n/, $sources)];
+ }
+ else
+ {
+ $source_files = [glob('/var/lib/apt/lists/*_source_Sources')];
+ }
}
foreach my $source (@{$source_files}) {
my $fh;
- if ($opt_uncompress || ($uncompress && $source =~ m/\.(?:gz|bz2)$/)) {
- $fh = IO::Uncompress::AnyUncompress->new($source);
- }
- else {
- $fh = FileHandle->new("<$source");
+ if ($useAptHelper)
+ {
+ my $good = open($fh, '-|', '/usr/lib/apt/apt-helper', 'cat-file', $source);
+ if (!$good)
+ {
+ warn "E: Couldn't run apt-helper to get contents of '$source': $!\n";
+ $errors = 1;
+ next;
+ }
}
- unless (defined $fh) {
- warn "E: Couldn't open $source\n";
- $errors = 1;
- next;
+ else
+ {
+ if ($opt_uncompress || ($uncompress && $source =~ m/\.(?:gz|bz2)$/)) {
+ $fh = IO::Uncompress::AnyUncompress->new($source);
+ }
+ else {
+ $fh = FileHandle->new("<$source");
+ }
+ unless (defined $fh) {
+ warn "E: Couldn't open $source\n";
+ $errors = 1;
+ next;
+ }
}
parsefh($fh, $source, 1);
- $fh->close;
+ close $fh;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git
More information about the devscripts-devel
mailing list