[Reproducible-builds] [strip-nondeterminism] 02/02: Add zip and jar support to dh_strip_nondeterminism

Andrew Ayer agwa at andrewayer.name
Sun Aug 31 16:58:43 UTC 2014


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 865af92937c6392ec6366c5d241f6fc09bc78344
Author: Andrew Ayer <agwa at andrewayer.name>
Date:   Sun Aug 31 09:57:20 2014 -0700

    Add zip and jar support to dh_strip_nondeterminism
---
 dh_strip_nondeterminism | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/dh_strip_nondeterminism b/dh_strip_nondeterminism
index 73ca4e8..13e2d53 100755
--- a/dh_strip_nondeterminism
+++ b/dh_strip_nondeterminism
@@ -70,6 +70,14 @@ sub testfile {
 		# silently ignores non-gzip files
 		push @nondeterministic_files, [$fn, \&handlers::gzip::normalize];
 	}
+	# zip
+	if (m/\.zip$/ && get_file_type($_) =~ m/Zip archive data/) {
+		push @nondeterministic_files, [$fn, \&handlers::zip::normalize];
+	}
+	# jar
+	if (m/\.jar$/ && get_file_type($_) =~ m/Zip archive data/) {
+		push @nondeterministic_files, [$fn, \&handlers::jar::normalize];
+	}
 }
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
@@ -184,6 +192,47 @@ sub normalize {
 	rename($out_filename, $filename) or error "$filename: unable to overwrite: rename: $!";
 }
 
+package handlers::zip;
+
+use Debian::Debhelper::Dh_Lib;
+use Archive::Zip;
+
+Archive::Zip::setErrorHandler(\&error);
+
+# A magic number from Archive::Zip for the earliest timestamp that
+# can be represented by a Zip file.  From the Archive::Zip source:
+# "Note, this isn't exactly UTC 1980, it's 1980 + 12 hours and 1
+# minute so that nothing timezoney can muck us up."
+use constant SAFE_EPOCH => 315576060;
+
+sub normalize {
+	my ($zip_filename, $filename_cmp) = @_;
+	$filename_cmp ||= sub { $a cmp $b };
+	my $zip = Archive::Zip->new($zip_filename);
+	my @filenames = sort $filename_cmp $zip->memberNames();
+	for my $filename (@filenames) {
+		my $member = $zip->removeMember($filename);
+		$zip->addMember($member);
+		$member->setLastModFileDateTimeFromUnix(SAFE_EPOCH);
+	}
+	$zip->overwrite();
+}
+
+package handlers::jar;
+
+sub _jar_filename_cmp {
+	# JAR files expect META-INF/MANIFEST.MF to be the first entry in the Zip archive.
+	return  0 if $a eq $b;
+	return -1 if $a eq 'META-INF/MANIFEST.MF';
+	return  1 if $b eq 'META-INF/MANIFEST.MF';
+	return $a cmp $b;
+}
+
+sub normalize {
+	my ($jar_filename) = @_;
+	handlers::zip::normalize($jar_filename, \&_jar_filename_cmp);
+}
+
 =head1 SEE ALSO
 
 L<debhelper(7)>

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



More information about the Reproducible-builds mailing list