[Reproducible-builds] [strip-nondeterminism] 04/06: Use object-oriented File::Temp interface
Andrew Ayer
agwa at andrewayer.name
Sun Sep 14 05:14:42 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 4e0fac1434acc58869cd5441cc1a58caa7c3b9f9
Author: Andrew Ayer <agwa at andrewayer.name>
Date: Sat Sep 13 21:28:20 2014 -0700
Use object-oriented File::Temp interface
---
lib/StripNondeterminism/handlers/gzip.pm | 18 ++++++++++--------
lib/StripNondeterminism/handlers/javadoc.pm | 15 ++++++++-------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/lib/StripNondeterminism/handlers/gzip.pm b/lib/StripNondeterminism/handlers/gzip.pm
index aa905e4..ca09ad0 100644
--- a/lib/StripNondeterminism/handlers/gzip.pm
+++ b/lib/StripNondeterminism/handlers/gzip.pm
@@ -21,7 +21,7 @@ package StripNondeterminism::handlers::gzip;
use strict;
use warnings;
-use File::Temp qw/tempfile/;
+use File::Temp;
use File::Basename;
use constant {
@@ -36,7 +36,6 @@ sub normalize {
my ($filename) = @_;
open(my $fh, '<', $filename) or die "Unable to open $filename for reading: $!";
- my ($out_fh, $out_filename) = tempfile(DIR => dirname($filename), UNLINK => 1);
# See RFC 1952
@@ -58,8 +57,10 @@ sub normalize {
$mtime = 0; # Zero out mtime (this is what `gzip -n` does)
# TODO: question: normalize some of the other fields, such as OS?
+ my $tempfile = File::Temp->new(DIR => dirname($filename));
+
# Write a new header
- print $out_fh pack('CCCCl<CC', $id1, $id2, $cm, $new_flg, $mtime, $xfl, $os);
+ print $tempfile pack('CCCCl<CC', $id1, $id2, $cm, $new_flg, $mtime, $xfl, $os);
if ($flg & FEXTRA) { # Copy through
# 0 1 2
@@ -70,7 +71,7 @@ sub normalize {
read($fh, $buf, 2) == 2 or die "$filename: Malformed gzip file";
my ($xlen) = unpack('v', $buf);
read($fh, $buf, $xlen) == $xlen or die "$filename: Malformed gzip file";
- print $out_fh pack('vA*', $xlen, $buf);
+ print $tempfile pack('vA*', $xlen, $buf);
}
if ($flg & FNAME) { # Read but do not copy through
# 0
@@ -91,7 +92,7 @@ sub normalize {
while (1) {
my $buf;
read($fh, $buf, 1) == 1 or die "$filename: Malformed gzip file";
- print $out_fh $buf;
+ print $tempfile $buf;
last if ord($buf) == 0;
}
}
@@ -111,12 +112,13 @@ sub normalize {
my $buf;
my $bytes_read = read($fh, $buf, 4096);
defined($bytes_read) or die "$filename: read failed: $!";
- print $out_fh $buf;
+ print $tempfile $buf;
last if $bytes_read == 0;
}
- chmod((stat($fh))[2] & 07777, $out_filename);
- rename($out_filename, $filename) or die "$filename: unable to overwrite: rename: $!";
+ chmod((stat($fh))[2] & 07777, $tempfile->filename);
+ rename($tempfile->filename, $filename) or die "$filename: unable to overwrite: rename: $!";
+ $tempfile->unlink_on_destroy(0);
return 1;
}
diff --git a/lib/StripNondeterminism/handlers/javadoc.pm b/lib/StripNondeterminism/handlers/javadoc.pm
index 4805432..41b020d 100644
--- a/lib/StripNondeterminism/handlers/javadoc.pm
+++ b/lib/StripNondeterminism/handlers/javadoc.pm
@@ -21,7 +21,7 @@ package StripNondeterminism::handlers::javadoc;
use strict;
use warnings;
-use File::Temp qw/tempfile/;
+use File::Temp;
use File::Basename;
sub is_javadoc_file {
@@ -37,29 +37,30 @@ sub normalize {
my ($filename) = @_;
open(my $fh, '<', $filename) or die "Unable to open $filename for reading: $!";
- my ($out_fh, $out_filename) = tempfile(DIR => dirname($filename), UNLINK => 1);
+ my $tempfile = File::Temp->new(DIR => dirname($filename));
# Strip the javadoc comment, which contains a timestamp.
# It should appear within first 10 lines.
while (defined(my $line = <$fh>) && $. <= 10) {
if ($line =~ /\<!-- Generated by javadoc .* --\>/) {
$line =~ s/\<!-- Generated by javadoc .* --\>//g;
- print $out_fh $line unless $line =~ /^\s*$/; # elide lines that are now whitespace-only
+ print $tempfile $line unless $line =~ /^\s*$/; # elide lines that are now whitespace-only
# Copy through rest of file
my $bytes_read;
my $buf;
while ($bytes_read = read($fh, $buf, 4096)) {
- print $out_fh $buf;
+ print $tempfile $buf;
}
defined($bytes_read) or die "$filename: read failed: $!";
# Rename temporary file over the file
- chmod((stat($fh))[2] & 07777, $out_filename);
- rename($out_filename, $filename) or die "$filename: unable to overwrite: rename: $!";
+ chmod((stat($fh))[2] & 07777, $tempfile->filename);
+ rename($tempfile->filename, $filename) or die "$filename: unable to overwrite: rename: $!";
+ $tempfile->unlink_on_destroy(0);
return 1;
}
- print $out_fh $line;
+ print $tempfile $line;
}
return 0;
--
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