[strip-nondeterminism] 01/02: Add cpio handler

Chris Lamb chris at chris-lamb.co.uk
Tue Jul 11 18:42:13 UTC 2017


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

lamby pushed a commit to branch experimental
in repository strip-nondeterminism.

commit 302772afc11d4fd67451843856c6f5610a35e721
Author: Bernhard M. Wiedemann <bwiedemann at suse.de>
Date:   Sat May 6 06:53:10 2017 +0000

    Add cpio handler
    
    it requires Archive::Cpio to do something useful,
    but will not add it as a hard requirement
    
    for Debian, this should require libarchive-cpio-perl to run+pass the tests
    and recommend it at runtime
---
 lib/File/StripNondeterminism.pm               |  6 +++++
 lib/File/StripNondeterminism/handlers/cpio.pm | 38 +++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm
index 887a7aa..f203283 100644
--- a/lib/File/StripNondeterminism.pm
+++ b/lib/File/StripNondeterminism.pm
@@ -23,6 +23,7 @@ use warnings;
 
 use POSIX qw(tzset);
 use File::StripNondeterminism::handlers::ar;
+use File::StripNondeterminism::handlers::cpio;
 use File::StripNondeterminism::handlers::gettext;
 use File::StripNondeterminism::handlers::gzip;
 use File::StripNondeterminism::handlers::jar;
@@ -60,6 +61,10 @@ sub get_normalizer_for_file {
 	if (m/\.a$/ && _get_file_type($_) =~ m/ar archive/) {
 		return \&File::StripNondeterminism::handlers::ar::normalize;
 	}
+	# cpio
+	if (m/\.cpio$/ && _get_file_type($_) =~ m/cpio archive/) {
+		return \&File::StripNondeterminism::handlers::cpio::normalize;
+	}
 	# gettext
 	if (m/\.g?mo$/ && _get_file_type($_) =~ m/GNU message catalog/) {
 		return \&File::StripNondeterminism::handlers::gettext::normalize;
@@ -109,6 +114,7 @@ sub get_normalizer_for_file {
 
 our %typemap = (
 	ar	=> \&File::StripNondeterminism::handlers::ar::normalize,
+	cpio	=> \&File::StripNondeterminism::handlers::cpio::normalize,
 	gettext	=> \&File::StripNondeterminism::handlers::gettext::normalize,
 	gzip	=> \&File::StripNondeterminism::handlers::gzip::normalize,
 	jar	=> \&File::StripNondeterminism::handlers::jar::normalize,
diff --git a/lib/File/StripNondeterminism/handlers/cpio.pm b/lib/File/StripNondeterminism/handlers/cpio.pm
new file mode 100644
index 0000000..c733731
--- /dev/null
+++ b/lib/File/StripNondeterminism/handlers/cpio.pm
@@ -0,0 +1,38 @@
+# Copyright © 2017 Bernhard M. Wiedemann <bmwiedemann at opensuse.org>
+#
+# This program 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.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+package File::StripNondeterminism::handlers::cpio;
+
+use strict;
+use warnings;
+
+sub normalize {
+	my ($file) = @_;
+	# if we cannot load the Cpio module, we just leave the file alone
+	# to not have Archive::Cpio as a hard requirement
+	# for strip-nondeterminism
+	eval {require Archive::Cpio} or return 0;
+	my $cpio = Archive::Cpio->new;
+	eval {$cpio->read($file)};
+	return 0 if $@; # not a cpio archive if it throws an error
+	foreach my $e ($cpio->get_files()) {
+		$e->{mtime} = $File::StripNondeterminism::canonical_time;
+	}
+	$cpio->write($file);
+	return 1;
+}
+
+1;

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