[Reproducible-builds] [misc] 01/01: Add a script to strip non-deterministic attributies in ar archives

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Aug 29 17:05:20 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 18c3849e1035171206173f275f7bc6e3b87a35d7
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Fri Aug 29 17:04:36 2014 +0000

    Add a script to strip non-deterministic attributies in ar archives
---
 normalizers/normalize_ar.py | 78 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/normalizers/normalize_ar.py b/normalizers/normalize_ar.py
new file mode 100755
index 0000000..15d6e3f
--- /dev/null
+++ b/normalizers/normalize_ar.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+#
+# normalize_ar: remove non-deterministic attributes of ar archives
+# Copyright © 2014 Jérémy Bobbio <lunar 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>
+
+GLOBAL_HEADER = "!<arch>\n"
+GLOBAL_HEADER_LENGTH = len(GLOBAL_HEADER)
+
+FILE_HEADER_LENGTH = 60
+FILE_MAGIC = "`\n"
+
+import os
+import sys
+
+def main():
+    f = open(sys.argv[1], "r+b")
+
+    buf = f.read(GLOBAL_HEADER_LENGTH)
+    if buf != GLOBAL_HEADER:
+        raise Exception, "Unable to find global header"
+
+    while True:
+        file_header_start = f.tell()
+        buf = f.read(FILE_HEADER_LENGTH)
+        if not buf:
+            break
+
+        # 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
+
+        # sanity checks
+        if len(buf) < FILE_HEADER_LENGTH:
+            raise IOError, "Incorrect header length"
+
+        if buf[58:60] != FILE_MAGIC:
+            raise IOError, "Incorrect file magic"
+        
+        file_size  = int(buf[48:58])
+
+        f.seek(file_header_start + 16, os.SEEK_SET)
+        # mtime
+        f.write("%-12d" % 0)
+        # owner
+        f.write("%-6d" % 0)
+        # group
+        f.write("%-6d" % 0)
+        # file mode
+        f.write("%-8o" % 0644)
+
+        # move to next member
+        f.seek(file_header_start + FILE_HEADER_LENGTH + file_size, os.SEEK_SET)
+
+if __name__ == '__main__':
+    main()

-- 
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