|
6 | 6 | # ZipFile: infolist, write, writestr, |
7 | 7 |
|
8 | 8 | import os |
9 | | -import zipfile2_6 as zipfile |
| 9 | +import zipfile_deterministic as zipfile |
10 | 10 | import sys |
11 | 11 | import time |
12 | 12 | import glob |
13 | 13 |
|
14 | 14 | xpiName = sys.argv[1] |
15 | 15 | exclusionsFile = sys.argv[2] |
16 | 16 | exclusions = [] |
17 | | -tmpfile = '../pkg/tmp.xpi' |
18 | 17 | compress = zipfile.ZIP_DEFLATED |
19 | 18 |
|
20 | 19 | with open(exclusionsFile) as f: |
21 | 20 | for line in f: |
22 | 21 | exclusions.extend(glob.glob(line.strip())) |
| 22 | +exclusions = map(lambda x: './'+x, exclusions) |
23 | 23 |
|
24 | 24 | xpiFile = zipfile.ZipFile(xpiName, mode='w', compression=compress) |
25 | 25 |
|
26 | | -def createTmpZipInfo(): |
27 | | - """ |
28 | | - Create a non-deterministic zip in order to use the file info |
29 | | - generated to create a deterministic zip |
30 | | - """ |
31 | | - xpiFileTmp = zipfile.ZipFile(tmpfile, mode='w', compression=compress) |
32 | | - for root,subfolders,files in os.walk('.'): |
33 | | - for fi in files: |
34 | | - filename = os.path.join(root,fi) |
35 | | - if filename not in map(lambda x: './'+x, exclusions): |
36 | | - xpiFileTmp.write(filename, compress_type=compress) |
37 | | - xpiFileTmp.close() |
38 | | - xpiFileTmp.infolist().sort(key = lambda x: x.filename) |
39 | | - return xpiFileTmp.infolist() |
40 | | - |
41 | | -def constructZipDet(): |
42 | | - """ |
43 | | - Create a deterministic zip by setting timestamps, |
44 | | - operating system, and pkzip version info to hard-coded |
45 | | - values. See the pkzip specification at |
46 | | - https://www.pkware.com/documents/casestudies/APPNOTE.TXT |
47 | | - """ |
48 | | - tmpInfo = createTmpZipInfo() |
49 | | - for info in tmpInfo: |
50 | | - info.date_time = time.gmtime(1378343307) |
51 | | - info.create_system = 3 # aka, UNIX |
52 | | - info.create_version = 20 |
53 | | - info.extract_version = 20 |
54 | | - info.external_attr = 0600 << 16 |
55 | | - info.file_size = long(info.file_size) # is int on some OS's |
56 | | - xpiFile.writestr(info, open(info.filename).read()) |
57 | | - |
58 | | -constructZipDet() |
| 26 | +xpiFile.write_from_directory('.', exclusions, compress_type=compress) |
59 | 27 | xpiFile.close() |
60 | | -os.remove(tmpfile) |
0 commit comments