Commit a812cfa3 authored by Andrew Ayer's avatar Andrew Ayer

Merge tag '0.019' into debian

strip-nondeterminism 0.019
parents f0b6de27 7024349d
......@@ -29,20 +29,23 @@ Getopt::Long::Configure(qw(no_ignore_case permute bundling));
my $cmd = $0;
$cmd =~ s/.*\///;
my $usage = "Usage: $cmd [-t|--type FILETYPE] [-T|--timestamp SECONDS] FILENAME\n";
my @opspec = (
'type|t=s', 'help|h', 'version|V', 'timestamp|T=i'
);
my $glop = {};
GetOptions($glop, @opspec) || die $usage;
if ($glop->{help}) {
my $usage = "Usage: $cmd [-t|--type FILETYPE] [-T|--timestamp SECONDS] [--clamp-timestamp] FILENAME\n";
my ($filetype, $timestamp, $clamp_timestamp, $want_help, $want_version);
my $getopt = Getopt::Long::Parser->new;
$getopt->configure(qw(no_ignore_case permute bundling));
$getopt->getoptions('type|t=s', \$filetype,
'timestamp|T=i', \$timestamp,
'clamp-timestamp!', \$clamp_timestamp,
'help|h', \$want_help,
'version|V', \$want_version) or die $usage;
if ($want_help) {
print $usage;
exit 0;
}
if ($glop->{version}) {
if ($want_version) {
print "$cmd version $File::StripNondeterminism::VERSION\n";
exit 0;
}
......@@ -50,15 +53,16 @@ if ($glop->{version}) {
$ENV{'TZ'} = 'UTC';
tzset();
$File::StripNondeterminism::canonical_time = $glop->{timestamp};
$File::StripNondeterminism::canonical_time = $timestamp;
$File::StripNondeterminism::clamp_time = $clamp_timestamp;
die $usage if @ARGV == 0;
for my $filename (@ARGV) {
my $normalizer;
if ($glop->{type}) {
$normalizer = File::StripNondeterminism::get_normalizer_by_name($glop->{type});
die $glop->{type} . ": Unknown file type\n" unless $normalizer;
if (defined $filetype) {
$normalizer = File::StripNondeterminism::get_normalizer_by_name($filetype);
die "$filetype: Unknown file type\n" unless $normalizer;
} else {
$normalizer = File::StripNondeterminism::get_normalizer_for_file($filename);
next unless $normalizer;
......@@ -99,6 +103,13 @@ the file name extension.
Instead of stripping timestamps from files, set them to the given number
of seconds since January 1, 1970.
=item B<--clamp-timestamp>
Only replace timestamps if they are later than the time specified to
B<--timestamp>. You can use this option to ensure that only timestamps
introduced as part of the build process are replaced. NOT YET IMPLEMENTED
FOR ALL FILE FORMATS.
=item B<-h>, B<--help>
Display this help message.
......
......@@ -31,9 +31,9 @@ use File::StripNondeterminism::handlers::png;
use File::StripNondeterminism::handlers::javaproperties;
use File::StripNondeterminism::handlers::zip;
our($VERSION, $canonical_time);
our($VERSION, $canonical_time, $clamp_time);
$VERSION = '0.018'; # 0.018
$VERSION = '0.019'; # 0.019
sub _get_file_type {
my $file=shift;
......
......@@ -55,8 +55,13 @@ sub normalize {
$new_flg &= ~FNAME; # Don't include filename
$new_flg &= ~FHCRC; # Don't include header CRC (not all implementations support it)
unless ($mtime == 0) { # Don't set a deterministic timestamp if there wasn't already a timestamp
# If there's no canonical time set, zero out the mtime (this is what `gzip -n` does):
$mtime = $File::StripNondeterminism::canonical_time // 0;
if (defined $File::StripNondeterminism::canonical_time) {
if (!$File::StripNondeterminism::clamp_time || $mtime > $File::StripNondeterminism::canonical_time) {
$mtime = $File::StripNondeterminism::canonical_time;
}
} else {
$mtime = 0; # gzip treats 0 as "no timestamp"
}
}
# TODO: question: normalize some of the other fields, such as OS?
......
......@@ -83,6 +83,8 @@ sub _jar_normalize_member {
# maven header should be within first 1kb of file
File::StripNondeterminism::handlers::zip::normalize_member($member,
\&File::StripNondeterminism::handlers::javaproperties::normalize);
} elsif ($member->fileName() =~ /\.jar$/) {
File::StripNondeterminism::handlers::zip::normalize_member($member, \&normalize);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment