[Reproducible-builds] [misc] 01/01: Perl version of the ar archive normalizer
Jérémy Bobbio
lunar at moszumanska.debian.org
Sat Aug 30 02:13:35 UTC 2014
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository misc.
commit 9edc96564be8e52cf8db0948b98cf25649ab1a0f
Author: Niko Tyni <ntyni at debian.org>
Date: Fri Aug 29 18:06:47 2014 -0700
Perl version of the ar archive normalizer
---
normalizers/normalize_ar.pl | 82 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/normalizers/normalize_ar.pl b/normalizers/normalize_ar.pl
new file mode 100755
index 0000000..1ac4d2b
--- /dev/null
+++ b/normalizers/normalize_ar.pl
@@ -0,0 +1,82 @@
+#!/usr/bin/perl -w
+# normalize_ar: remove non-deterministic attributes of ar archives
+# Copyright © 2014 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2014 Niko Tyni <ntyni at debian.org>
+#
+# This program 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.
+#
+# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Some code borrowed from ArFile
+# Copyright (C) 2007 Stefano Zacchiroli <zack at debian.org>
+# Copyright (C) 2007 Filippo Giunchedi <filippo at debian.org>
+
+use strict;
+
+use Fcntl q/SEEK_SET/;
+
+my $GLOBAL_HEADER = "!<arch>\n";
+my $GLOBAL_HEADER_LENGTH = length $GLOBAL_HEADER;
+
+my $FILE_HEADER_LENGTH = 60;
+my $FILE_MAGIC = "`\n";
+
+my $buf;
+
+die("Usage: $0 <file>\n") if !@ARGV;
+my $file = shift;
+
+open(F, '+<', $file)
+ or die("failed to open $file for read+write: $!");
+
+read F, $buf, $GLOBAL_HEADER_LENGTH;
+die("Unable to find global header") if $buf ne $GLOBAL_HEADER;
+
+while (1) {
+ my $file_header_start = tell F;
+ my $count = read F, $buf, $FILE_HEADER_LENGTH;
+ die "reading $file failed: $!" if !defined $count;
+ last if $count == 0;
+
+ # http://en.wikipedia.org/wiki/Ar_(Unix)
+ #from to Name Format
+ #0 15 File name ASCII
+ #16 27 File modification date Decimal
+ #28 33 Owner ID Decimal
+ #34 39 Group ID Decimal
+ #40 47 File mode Octal
+ #48 57 File size in bytes Decimal
+ #58 59 File magic \140\012
+
+ # FIXME: is this correct?
+ last if $count == 1 and eof(F) and $buf eq "\n";
+
+ die "Incorrect header length"
+ if length $buf != $FILE_HEADER_LENGTH;
+ die "Incorrect file magic"
+ if substr($buf, 58, length($FILE_MAGIC)) ne $FILE_MAGIC;
+
+ my $file_size = substr($buf, 48, 10);
+ seek F, $file_header_start + 16, SEEK_SET;
+
+ # mtime
+ syswrite F, sprintf("%-12d", 0);
+ # owner
+ syswrite F, sprintf("%-6d", 0);
+ # group
+ syswrite F, sprintf("%-6d", 0);
+ # file mode
+ syswrite F, sprintf("%-8o", 0644);
+
+ # move to next member
+ seek F, $file_header_start + $FILE_HEADER_LENGTH + $file_size, SEEK_SET;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git
More information about the Reproducible-builds
mailing list