[Reproducible-commits] [strip-nondeterminism] 02/02: Replace generated times in files generated by docbook-to-man.

Andrew Ayer agwa at andrewayer.name
Thu Feb 5 17:34:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

agwa-guest pushed a commit to branch master
in repository strip-nondeterminism.

commit 966f648b6d4adcc2491cb84d4e72ded4eaad5b89
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Jan 24 12:21:25 2015 +0000

    Replace generated times in files generated by docbook-to-man.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
    Closes: #776140
---
 lib/File/StripNondeterminism.pm                    |  6 +++
 .../StripNondeterminism/handlers/docbooktoman.pm   | 59 ++++++++++++++++++++++
 t/docbooktoman.t                                   | 51 +++++++++++++++++++
 3 files changed, 116 insertions(+)

diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm
index 8fcaf23..59df3f0 100644
--- a/lib/File/StripNondeterminism.pm
+++ b/lib/File/StripNondeterminism.pm
@@ -22,6 +22,7 @@ use strict;
 use warnings;
 
 use File::StripNondeterminism::handlers::ar;
+use File::StripNondeterminism::handlers::docbooktoman;
 use File::StripNondeterminism::handlers::gzip;
 use File::StripNondeterminism::handlers::jar;
 use File::StripNondeterminism::handlers::javadoc;
@@ -53,6 +54,10 @@ sub get_normalizer_for_file {
 	if (m/\.a$/ && _get_file_type($_) =~ m/ar archive/) {
 		return \&File::StripNondeterminism::handlers::ar::normalize;
 	}
+	# docbook-to-man
+	if (m/\.\d$/ && _get_file_type($_) =~ m/troff/) {
+		return \&File::StripNondeterminism::handlers::docbooktoman::normalize;
+	}
 	# gzip
 	if (m/\.(gz|dz)$/ && _get_file_type($_) =~ m/gzip compressed data/) {
 		return \&File::StripNondeterminism::handlers::gzip::normalize;
@@ -87,6 +92,7 @@ sub get_normalizer_for_file {
 sub get_normalizer_by_name {
 	$_ = shift;
 	return \&File::StripNondeterminism::handlers::ar::normalize if $_ eq 'ar';
+	return \&File::StripNondeterminism::handlers::docbooktoman::normalize if $_ eq 'docbooktoman';
 	return \&File::StripNondeterminism::handlers::gzip::normalize if $_ eq 'gzip';
 	return \&File::StripNondeterminism::handlers::jar::normalize if $_ eq 'jar';
 	return \&File::StripNondeterminism::handlers::javadoc::normalize if $_ eq 'javadoc';
diff --git a/lib/File/StripNondeterminism/handlers/docbooktoman.pm b/lib/File/StripNondeterminism/handlers/docbooktoman.pm
new file mode 100644
index 0000000..2760409
--- /dev/null
+++ b/lib/File/StripNondeterminism/handlers/docbooktoman.pm
@@ -0,0 +1,59 @@
+#
+# Copyright 2015 Chris Lamb <lamby at debian.org>
+#
+# This file is part of strip-nondeterminism.
+#
+# strip-nondeterminism is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# strip-nondeterminism is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with strip-nondeterminism.  If not, see <http://www.gnu.org/licenses/>.
+#
+package File::StripNondeterminism::handlers::docbooktoman;
+
+use strict;
+use warnings;
+
+use File::Temp;
+use File::Basename;
+use POSIX qw( strftime );
+
+sub normalize {
+	my ($filename) = @_;
+
+	open(my $fh, '<', $filename)
+		or die "Unable to open $filename for reading: $!";
+
+	my $modified = 0;
+	my $tempfile = File::Temp->new(DIR => dirname($filename));
+	my $canonical_time = $File::StripNondeterminism::canonical_time // 0;
+
+	# Format is specified in docbook-to-man:Instant/main.c
+	my $timestamp = strftime('%a %d %b %Y, %R', localtime($canonical_time));
+
+	while (defined(my $line = <$fh>)) {
+		if ($line =~ s/(?<=^\.\\" created by instant \/ docbook-to-man, ).*/$timestamp/g) {
+			$modified = 1;
+		}
+
+		print $tempfile $line;
+	}
+
+	if ($modified) {
+		chmod((stat($fh))[2] & 07777, $tempfile->filename);
+		rename($tempfile->filename, $filename)
+			or die "$filename: unable to overwrite: rename: $!";
+		$tempfile->unlink_on_destroy(0);
+	}
+
+	return $modified;
+}
+
+1;
diff --git a/t/docbooktoman.t b/t/docbooktoman.t
new file mode 100644
index 0000000..8072c42
--- /dev/null
+++ b/t/docbooktoman.t
@@ -0,0 +1,51 @@
+#!perl
+
+#
+# Copyright 2015 Chris Lamb <lamby at debian.org>
+#
+# This file is part of strip-nondeterminism.
+#
+# strip-nondeterminism is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# strip-nondeterminism is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with strip-nondeterminism.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+use File::Temp 'tempdir';
+use Test::More tests => 2;
+use File::StripNondeterminism;
+
+$dir = tempdir( CLEANUP => 1 );
+$path = "$dir/connect-proxy.1";
+
+open(my $fh, '>', $path) or die("error opening $path");
+print $fh <<'EOF';
+.TH "CONNECT-PROXY" "1" 
+.SH "NAME" 
+connect-proxy \(em connect over SOCKS4/5 proxy 
+ 
+.\" created by instant / docbook-to-man, Sat 24 Jan 2015, 11:43 
+EOF
+close $fh;
+
+$normalizer = File::StripNondeterminism::get_normalizer_for_file($path);
+isnt(undef, $normalizer);
+$normalizer->($path);
+
+open FILE,$path or die("error opening $path");
+local $/ = undef;
+is(<FILE>, <<'EOF');
+.TH "CONNECT-PROXY" "1" 
+.SH "NAME" 
+connect-proxy \(em connect over SOCKS4/5 proxy 
+ 
+.\" created by instant / docbook-to-man, Thu 01 Jan 1970, 00:00
+EOF

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/strip-nondeterminism.git



More information about the Reproducible-commits mailing list