Hello.

The attached patch aims to fix:

  
https://reproducible.debian.net/issues/timestamps_in_php_registry_files_issue.html

In terms of bugs, there is currently #750697 but I think it's against
the wrong package - it should be against PEAR itself. (I first fixed
PEAR but the patch was a bit too invasive).


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
From 4448ecb4965e998d1ea5ef3149e486b87151622a Mon Sep 17 00:00:00 2001
From: Chris Lamb <la...@debian.org>
Date: Sat, 24 Jan 2015 02:02:37 +0000
Subject: [PATCH] Strip _lastmodified times from PEAR registry files.

Signed-off-by: Chris Lamb <la...@debian.org>
---
 lib/File/StripNondeterminism.pm                    |  6 ++
 .../StripNondeterminism/handlers/pearregistry.pm   | 65 ++++++++++++++++++++++
 t/pearregistry.t                                   | 38 +++++++++++++
 3 files changed, 109 insertions(+)
 create mode 100644 lib/File/StripNondeterminism/handlers/pearregistry.pm
 create mode 100644 t/pearregistry.t

diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm
index e6dd1ab..ca182bb 100644
--- a/lib/File/StripNondeterminism.pm
+++ b/lib/File/StripNondeterminism.pm
@@ -26,6 +26,7 @@ use File::StripNondeterminism::handlers::gzip;
 use File::StripNondeterminism::handlers::jar;
 use File::StripNondeterminism::handlers::javadoc;
 use File::StripNondeterminism::handlers::pe;
+use File::StripNondeterminism::handlers::pearregistry;
 use File::StripNondeterminism::handlers::pomproperties;
 use File::StripNondeterminism::handlers::zip;
 
@@ -64,6 +65,10 @@ sub get_normalizer_for_file {
 	if (m/\.html$/ && File::StripNondeterminism::handlers::javadoc::is_javadoc_file($_)) {
 		return \&File::StripNondeterminism::handlers::javadoc::normalize;
 	}
+	# pear registry
+	if (m/\.reg$/ && File::StripNondeterminism::handlers::pearregistry::is_registry_file($_)) {
+		return \&File::StripNondeterminism::handlers::pearregistry::normalize;
+	}
 	# PE executables
 	if (m/\.(exe|dll|cpl|ocx|sys|scr|drv|efi|fon)/ && _get_file_type($_) =~ m/PE32.? executable/) {
 		return \&File::StripNondeterminism::handlers::pe::normalize;
@@ -86,6 +91,7 @@ sub get_normalizer_by_name {
 	return \&File::StripNondeterminism::handlers::jar::normalize if $_ eq 'jar';
 	return \&File::StripNondeterminism::handlers::javadoc::normalize if $_ eq 'javadoc';
 	return \&File::StripNondeterminism::handlers::pe::normalize if $_ eq 'pe';
+	return \&File::StripNondeterminism::handlers::pearregistry::normalize if $_ eq 'pearregistry';
 	return \&File::StripNondeterminism::handlers::pomproperties::normalize if $_ eq 'pomproperties';
 	return \&File::StripNondeterminism::handlers::zip::normalize if $_ eq 'zip';
 	return undef;
diff --git a/lib/File/StripNondeterminism/handlers/pearregistry.pm b/lib/File/StripNondeterminism/handlers/pearregistry.pm
new file mode 100644
index 0000000..d93ddb3
--- /dev/null
+++ b/lib/File/StripNondeterminism/handlers/pearregistry.pm
@@ -0,0 +1,65 @@
+#
+# Copyright 2015 Chris Lamb <la...@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::pearregistry;
+
+use strict;
+use warnings;
+
+use File::Temp;
+use File::Basename;
+
+sub is_registry_file {
+	my ($filename) = @_;
+
+	# Registry files will always start with "a:"
+	my $fh;
+	my $str;
+	return open($fh, '<', $filename) && read($fh, $str, 2) && $str =~ "^a:";
+}
+
+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;
+
+	while (defined(my $line = <$fh>)) {
+		# Normalize _lastmodified
+		if ($line =~ s/(?<=s:13:"_lastmodified";i:)\d+(?=;)/$canonical_time/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/pearregistry.t b/t/pearregistry.t
new file mode 100644
index 0000000..e4bbe76
--- /dev/null
+++ b/t/pearregistry.t
@@ -0,0 +1,38 @@
+#!perl
+
+#
+# Copyright 2015 Chris Lamb <la...@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/test.reg";
+
+open(my $fh, '>', $path) or die("error opening $path");
+print $fh 'a:1:{s:13:"_lastmodified";i:1422064771;}';
+close $fh;
+
+$normalizer = File::StripNondeterminism::get_normalizer_for_file($path);
+isnt(undef, $normalizer);
+$normalizer->($path);
+
+open FILE,$path or die("error opening $path");
+is(<FILE>, 'a:1:{s:13:"_lastmodified";i:0;}');
-- 
2.1.0

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to