Fix the permission setting in common.ZipWriteStr()
When passing a ZipInfo instance to common.ZipWriteStr(), the external_attr attribute should not be overwritten unless specified. We didn't have the issue previously because we were calling ZipFile.writestr() directly until [1] merged. [1] commit2ed665a033
. Bug: http://b/21309935 Change-Id: I8c0190362c60d7d78965ecfe5e484f8398ddc5f2 (cherry picked from commit9773465409
)
This commit is contained in:
@@ -862,7 +862,7 @@ def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
|
||||
zipfile.ZIP64_LIMIT = saved_zip64_limit
|
||||
|
||||
|
||||
def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=0o644,
|
||||
def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
|
||||
compress_type=None):
|
||||
"""Wrap zipfile.writestr() function to work around the zip64 limit.
|
||||
|
||||
@@ -881,6 +881,8 @@ def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=0o644,
|
||||
if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
|
||||
zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname)
|
||||
zinfo.compress_type = zip_file.compression
|
||||
if perms is None:
|
||||
perms = 0o644
|
||||
else:
|
||||
zinfo = zinfo_or_arcname
|
||||
|
||||
@@ -888,8 +890,11 @@ def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=0o644,
|
||||
if compress_type is not None:
|
||||
zinfo.compress_type = compress_type
|
||||
|
||||
# If perms is given, it has a priority.
|
||||
if perms is not None:
|
||||
zinfo.external_attr = perms << 16
|
||||
|
||||
# Use a fixed timestamp so the output is repeatable.
|
||||
zinfo.external_attr = perms << 16
|
||||
zinfo.date_time = (2009, 1, 1, 0, 0, 0)
|
||||
|
||||
zip_file.writestr(zinfo, data)
|
||||
|
Reference in New Issue
Block a user