Skip to content

Commit 7490f72

Browse files
committed
Make sure files are deterministically ordered before zipping
1 parent b36e5fb commit 7490f72

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

utils/create_xpi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Uses the Python zip implementation to create deterministic XPI's
44
# Author: Yan Zhu, yan@mit.edu
55

6+
# ZipFile: infolist, write, writestr,
7+
68
import os
79
import zipfile2_6 as zipfile
810
import sys
@@ -26,13 +28,18 @@ def createTmpZipInfo():
2628
Create a non-deterministic zip in order to use the file info
2729
generated to create a deterministic zip
2830
"""
29-
xpiFileTmp = zipfile.ZipFile(tmpfile, mode='w')
31+
xpiFileTmp = zipfile.ZipFile(tmpfile, mode='w', compression=compress)
32+
filesToAdd = [] # need to create arr for deterministic sorting
3033
for root,subfolders,files in os.walk('.'):
3134
for fi in files:
3235
filename = os.path.join(root,fi)
3336
if filename not in map(lambda x: './'+x, exclusions):
34-
xpiFileTmp.write(filename, compress_type=compress)
37+
filesToAdd.append(filename)
38+
filesToAdd.sort()
39+
for filename in filesToAdd:
40+
xpiFileTmp.write(filename, compress_type=compress)
3541
xpiFileTmp.close()
42+
xpiFileTmp.infolist().sort(key = lambda x: x.filename)
3643
return xpiFileTmp.infolist()
3744

3845
def constructZipDet():

0 commit comments

Comments
 (0)