[Reproducible-commits] [strip-nondeterminism] 01/02: Strip _lastmodified times from PEAR registry files.

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 7eedde0b54dd8559441a6a9633027a4e8e9e2230
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Jan 24 02:02:37 2015 +0000

    Strip _lastmodified times from PEAR registry files.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
    Closes: #776138
---
 lib/File/StripNondeterminism.pm                    |  6 ++
 .../StripNondeterminism/handlers/pearregistry.pm   | 65 ++++++++++++++++++++++
 t/pearregistry.t                                   | 38 +++++++++++++
 3 files changed, 109 insertions(+)

diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm
index 492e189..8fcaf23 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..22e4eb0
--- /dev/null
+++ b/lib/File/StripNondeterminism/handlers/pearregistry.pm
@@ -0,0 +1,65 @@
+#
+# 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::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 <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/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;}');

-- 
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