Skip to content

Commit 51480ad

Browse files
committed
Set zip info deterministically
1 parent 2a875b2 commit 51480ad

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

utils/create_xpi.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,32 @@
1111
with open(exclusionsFile) as f:
1212
for line in f:
1313
exclusions.extend(glob.glob(line.strip()))
14-
print(exclusions)
1514

1615
xpiFile = zipfile.ZipFile(xpiName, mode='w')
1716

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
33+
1834
for root,subfolders,files in os.walk('.'):
1935
for fi in files:
2036
filename = os.path.join(root,fi)
2137
if filename not in map(lambda x: './'+x, exclusions):
22-
print(filename)
23-
info = zipfile.ZipInfo(filename, time.gmtime(1378343307))
24-
xpiFile.writestr(info, '')
38+
print("Adding to zip: "+filename)
39+
info = constructZipInfo(filename)
40+
xpiFile.writestr(info, open(filename).read())
2541

2642
xpiFile.close()

0 commit comments

Comments
 (0)