[Reproducible-commits] [strip-nondeterminism] 01/01: TIFF support

Chris Lamb chris at chris-lamb.co.uk
Sat Jul 23 18:43:40 UTC 2016


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

lamby pushed a commit to branch lamby/wip/tiff
in repository strip-nondeterminism.

commit e9644179731a5d6c8c34c548d1c5b5569a9d33ee
Author: Chris Lamb <lamby at debian.org>
Date:   Fri Jun 24 10:23:23 2016 +0200

    TIFF support
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 lib/File/StripNondeterminism.pm               |  6 +++
 lib/File/StripNondeterminism/handlers/tiff.pm | 55 +++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm
index f69c0c0..29760a6 100644
--- a/lib/File/StripNondeterminism.pm
+++ b/lib/File/StripNondeterminism.pm
@@ -27,6 +27,7 @@ use File::StripNondeterminism::handlers::jar;
 use File::StripNondeterminism::handlers::javadoc;
 use File::StripNondeterminism::handlers::pearregistry;
 use File::StripNondeterminism::handlers::png;
+use File::StripNondeterminism::handlers::tiff;
 use File::StripNondeterminism::handlers::javaproperties;
 use File::StripNondeterminism::handlers::zip;
 
@@ -73,6 +74,10 @@ sub get_normalizer_for_file {
 	if (m/\.png$/ && _get_file_type($_) =~ m/PNG image data/) {
 		return \&File::StripNondeterminism::handlers::png::normalize;
 	}
+	# TIFF
+	if (m/\.tiff?$/ && _get_file_type($_) =~ m/TIFF image data/) {
+		return \&File::StripNondeterminism::handlers::tiff::normalize;
+	}
 	# pom.properties, version.properties
 	if (m/(pom|version)\.properties$/ && File::StripNondeterminism::handlers::javaproperties::is_java_properties_file($_)) {
 		return \&File::StripNondeterminism::handlers::javaproperties::normalize;
@@ -92,6 +97,7 @@ sub get_normalizer_by_name {
 	return \&File::StripNondeterminism::handlers::javadoc::normalize if $_ eq 'javadoc';
 	return \&File::StripNondeterminism::handlers::pearregistry::normalize if $_ eq 'pearregistry';
 	return \&File::StripNondeterminism::handlers::png::normalize if $_ eq 'png';
+	return \&File::StripNondeterminism::handlers::tiff::normalize if $_ eq 'tiff';
 	return \&File::StripNondeterminism::handlers::javaproperties::normalize if $_ eq 'javaproperties';
 	return \&File::StripNondeterminism::handlers::zip::normalize if $_ eq 'zip';
 	return undef;
diff --git a/lib/File/StripNondeterminism/handlers/tiff.pm b/lib/File/StripNondeterminism/handlers/tiff.pm
new file mode 100644
index 0000000..2852eb0
--- /dev/null
+++ b/lib/File/StripNondeterminism/handlers/tiff.pm
@@ -0,0 +1,55 @@
+#
+# Copyright 2016 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::tiff;
+
+use strict;
+use warnings;
+
+use File::Basename qw/dirname/;
+use POSIX qw/strftime/;
+use Archive::Zip;
+
+sub normalize {
+	my ($filename) = @_;
+
+	my $canonical_time = $File::StripNondeterminism::canonical_time;
+
+	my $tempfile = File::Temp->new(DIR => dirname($filename));
+
+	open(my $fh, '+<', $filename) or die "$filename: open: $!";
+	read($fh, my $magic, 4); $magic eq "\x49\x49\x2a\x00"
+		or die "$filename: does not appear to be a TIFF";
+	print $tempfile $magic;
+
+	my $bytes_read;
+	my $buf;
+	while ($bytes_read = read($fh, $buf, 4096)) {
+		print $tempfile $buf;
+	}
+	defined($bytes_read) or die "$filename: read failed: $!";
+
+	chmod((stat($fh))[2] & 07777, $tempfile->filename);
+	rename($tempfile->filename, $filename)
+		or die "$filename: unable to overwrite: rename: $!";
+	$tempfile->unlink_on_destroy(0);
+
+	close $fh;
+}
+
+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