[debhelper-devel] [debhelper] 05/08: dh_installman: Replace zcat with new open_gz
Niels Thykier
nthykier at moszumanska.debian.org
Sun May 1 08:06:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit 2dc8e5818e52c840d9f4da8d8fb627660da19d64
Author: Niels Thykier <niels at thykier.net>
Date: Sun May 1 07:42:42 2016 +0000
dh_installman: Replace zcat with new open_gz
Signed-off-by: Niels Thykier <niels at thykier.net>
---
Debian/Debhelper/Dh_Lib.pm | 16 ++++++++++++++++
dh_installman | 19 ++++++++++---------
doc/PROGRAMMING | 6 ++++++
3 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 71cb9d7..7daa5f4 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -36,6 +36,7 @@ use vars qw(@EXPORT %dh);
&get_source_date_epoch &is_cross_compiling
&generated_file &autotrigger &package_section
&restore_file_on_clean &restore_all_files
+ &open_gz
);
# The Makefile changes this if debhelper is installed in a PREFIX.
@@ -1397,6 +1398,21 @@ sub restore_all_files {
return;
}
+sub open_gz {
+ my ($file) = @_;
+ my $fd;
+ eval {
+ require PerlIO::gzip;
+ };
+ if ($@) {
+ open($fd, '-|', 'gzip', '-dc', $file)
+ or die("gzip -dc $file failed: $!");
+ } else {
+ open($fd, '<:gzip', $file)
+ or die("open $file [<:gzip] failed: $!");
+ }
+ return $fd;
+}
1
diff --git a/dh_installman b/dh_installman
index 93f9356..12d473c 100755
--- a/dh_installman
+++ b/dh_installman
@@ -121,23 +121,23 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
$gz=$2;
}
- my $section;
+ my ($fd, $section);
# See if there is a .TH or .Dt entry in the man page. If so,
# we'll pull the section field from that.
if ($gz) {
- open (IN, "zcat $page|") or die "$page: $!";
+ $fd = open_gz($page) or die "$page: $!";
}
else {
- open(IN, '<', $page) or die "$page: $!";
+ open($fd, '<', $page) or die "$page: $!";
}
- while (<IN>) {
+ while (<$fd>) {
if (/^\.TH\s+\S+\s+"?(\d+[^"\s]*)"?/ ||
/^\.Dt\s+\S+\s+(\d+[^\s]*)/) {
$section=$1;
last;
}
}
- close(IN);
+ close($fd);
# Failing that, we can try to get it from the filename.
if (! $section) {
($section)=$basename=~m/.*\.([1-9]\S*)/;
@@ -228,14 +228,15 @@ sub find_so_man {
}
# Test first line of file for the .so thing.
+ my $fd;
if (/\.gz$/) {
- open (SOTEST, "zcat $_|") or die "$_: $!";
+ $fd = open_gz($_) or die "$_: $!";
}
else {
- open(SOTEST, '<', $_) || die "$_: $!";
+ open($fd, '<', $_) || die "$_: $!";
}
- my $l=<SOTEST>;
- close SOTEST;
+ my $l = <$fd>;
+ close($fd);
if (! defined $l) {
error("failed to read $_");
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index 1f03bdf..9944929 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -323,6 +323,12 @@ install_lib($src, $dest)
Installs a library at the path $src into $dest. The parent
dir of $dest must exist (can be created with install_dir).
This is intended for installing libraries.
+open_gz($file)
+ Open $file, read from it as a gzip-compressed file and return
+ the file handle.
+ Depending on runtime features, it might be a pipe from an
+ external process (which will die with a "SIGPIPE" if you
+ do not consume all the input)
Sequence Addons:
---------------
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list