|
7 | 7 | xpiName = sys.argv[1] |
8 | 8 | exclusionsFile = sys.argv[2] |
9 | 9 | exclusions = [] |
| 10 | +tmpfile = '../pkg/tmp.xpi' |
10 | 11 |
|
11 | 12 | with open(exclusionsFile) as f: |
12 | 13 | for line in f: |
13 | 14 | exclusions.extend(glob.glob(line.strip())) |
14 | 15 |
|
15 | 16 | xpiFile = zipfile.ZipFile(xpiName, mode='w') |
16 | 17 |
|
17 | | -def constructZipInfo(filename): |
18 | | - """Create deterministic ZIP metadata for a given file""" |
19 | | - info = zipfile.ZipInfo(filename, time.gmtime(1378343307)) |
20 | | - info.compress_type = 0 |
21 | | - info.comment = '' |
22 | | - info.extra = '' |
23 | | - info.create_system = 3 |
24 | | - info.create_version = 20 |
25 | | - info.extract_version = 20 |
26 | | - if os.path.isfile(filename): |
27 | | - info.external_attr = 0664 << 16L |
28 | | - elif os.path.isdir(filename): |
29 | | - info.external_attr = 04775 << 16L |
30 | | - # info.external_attr = 2176057344L |
31 | | - info.volume = 0 |
32 | | - return info |
| 18 | +def createTmpZipInfo(): |
| 19 | + """ |
| 20 | + Create a non-deterministic zip in order to use the file info |
| 21 | + generated to create a deterministic zip |
| 22 | + """ |
| 23 | + xpiFileTmp = zipfile.ZipFile(tmpfile, mode='w') |
| 24 | + for root,subfolders,files in os.walk('.'): |
| 25 | + for fi in files: |
| 26 | + filename = os.path.join(root,fi) |
| 27 | + if filename not in map(lambda x: './'+x, exclusions): |
| 28 | + xpiFileTmp.write(filename) |
| 29 | + xpiFileTmp.close() |
| 30 | + return xpiFileTmp.infolist() |
33 | 31 |
|
34 | | -for root,subfolders,files in os.walk('.'): |
35 | | - for fi in files: |
36 | | - filename = os.path.join(root,fi) |
37 | | - if filename not in map(lambda x: './'+x, exclusions): |
38 | | - print("Adding to zip: "+filename) |
39 | | - info = constructZipInfo(filename) |
40 | | - xpiFile.writestr(info, open(filename).read()) |
| 32 | +def constructZipDet(): |
| 33 | + """ |
| 34 | + Create a deterministic zip by setting timestamps and |
| 35 | + system/version info to hard-coded values |
| 36 | + """ |
| 37 | + tmpInfo = createTmpZipInfo() |
| 38 | + for info in tmpInfo: |
| 39 | + info.date_time = time.gmtime(1378343307) |
| 40 | + info.create_system = 3 |
| 41 | + info.create_version = 20 |
| 42 | + info.extract_version = 20 |
| 43 | + print("adding to zip: "+info.filename) |
| 44 | + xpiFile.writestr(info, open(info.filename).read()) |
41 | 45 |
|
| 46 | +constructZipDet() |
42 | 47 | xpiFile.close() |
| 48 | +os.remove(tmpfile) |
0 commit comments