Skip to content
Commits on Source (6)
......@@ -84,6 +84,7 @@ for (split(/,/, $normalizers // '')) {
$File::StripNondeterminism::canonical_time = $timestamp;
$File::StripNondeterminism::clamp_time = $clamp_timestamp;
$File::StripNondeterminism::verbose = $verbose;
die $usage if @ARGV == 0;
......
t/fixtures/ar/long_member_name.a.in
t/fixtures/ar/long_member_name.a.out
t/fixtures/ar/longnames_symtab.a.in
t/fixtures/ar/longnames_symtab.a.out
t/fixtures/ar/symbol_table.a.in
t/fixtures/ar/symbol_table.a.out
......@@ -23,7 +23,7 @@ use warnings;
use POSIX qw(tzset);
our($VERSION, $canonical_time, $clamp_time);
our($VERSION, $canonical_time, $clamp_time, $verbose);
$VERSION = '1.5.0'; # <https://semver.org/>
......
......@@ -65,15 +65,35 @@ sub normalize {
die "Incorrect file magic"
if substr($buf, 58, length($FILE_MAGIC)) ne $FILE_MAGIC;
# $member_id is the member's filename if it's short
# enough to fit in 16 characters. Otherwise it's a
# "/number" index in the table of long member names '//'
# (SysV/GNU), or a #1/ prefixed length (BSD)
my $member_id = substr($buf, 0, 16);
my $file_mode = oct(substr($buf, 40, 8));
my $file_size = substr($buf, 48, 10);
die "Incorrect file size"
if $file_size < 1;
# Don't touch the System V/GNU table of long filenames
# '//', it's a different format and already
# deterministic.
if (substr($member_id, 0, 3) eq "// ") {
goto NEXT_MEMBER;
}
seek $fh, $file_header_start + 16, SEEK_SET;
# mtime
if ($File::StripNondeterminism::verbose
&& $File::StripNondeterminism::canonical_time
&& substr($member_id, 0, 2) eq "/ ") {
print "Setting symbols table's mtime in $file to: "
. gmtime($File::StripNondeterminism::canonical_time)
. ". GNU ar cannot do this.\n";
}
syswrite $fh,
sprintf("%-12d", $File::StripNondeterminism::canonical_time // 0);
# owner
......@@ -81,10 +101,15 @@ sub normalize {
# group
syswrite $fh, sprintf("%-6d", 0);
# file mode
# Don't touch the pseudo-"filemode" of the symbols table '/ '
if (substr($member_id, 0, 2) eq "/ ") {
goto NEXT_MEMBER;
}
syswrite $fh,
sprintf("%-8o", ($file_mode & oct(100)) ? oct(755) : oct(644));
# move to next member
NEXT_MEMBER:
my $padding = $file_size % 2;
seek $fh,
$file_header_start + $FILE_HEADER_LENGTH + $file_size + $padding,
......
......@@ -53,6 +53,7 @@ for (File::StripNondeterminism::all_normalizers()) {
File::StripNondeterminism::enable_normalizer($_);
}
# = 2015-02-05 10:09:31
$File::StripNondeterminism::canonical_time = 1423159771;
my @fixtures = glob('t/fixtures/*/*.in');
......
!<arch>
// 28 `
filename_longer_than16.txt/
/0 1423159771 1001 0 100664 45 `
a file with a name longer than 16 characters
!<arch>
// 28 `
filename_longer_than16.txt/
/0 1423159771 0 0 644 45 `
a file with a name longer than 16 characters