Fix 2009-01-01 timestamps in releasetools to always be UTC
The usage of datetime.fromtimestamp previously resulted in the build or signing machine's local timezone affecting the Unix timestamp ultimately applied to images generated by add_img_to_target_files. The go/ab build outputs would use 2009-01-01 00:00 UTC, for example, but local builds and the release signed images (generated through go/ab-sign) would use 2009-01-01 00:00 PST. This change makes the timestamps always use UTC. Bug: 80600931 Bug: 80093599 Test: 'm -j droid dist' and verified timestamps in resulting target_files zip. Change-Id: Ic2a19591519850c249f78254e1464aa6839bfc6c
This commit is contained in:
parent
bb937a6b69
commit
e6d547d53a
2 changed files with 13 additions and 20 deletions
|
@ -72,10 +72,12 @@ OPTIONS.replace_verity_public_key = False
|
|||
OPTIONS.replace_verity_private_key = False
|
||||
OPTIONS.is_signing = False
|
||||
|
||||
|
||||
# Partitions that should have their care_map added to META/care_map.txt.
|
||||
PARTITIONS_WITH_CARE_MAP = ('system', 'vendor', 'product', 'product-services')
|
||||
|
||||
# Use a fixed timestamp (01/01/2009 00:00:00 UTC) for files when packaging
|
||||
# images. (b/24377993, b/80600931)
|
||||
FIXED_FILE_TIMESTAMP = (datetime.datetime(2009, 1, 1, 0, 0, 0, 0, None)
|
||||
- datetime.datetime.utcfromtimestamp(0)).total_seconds()
|
||||
|
||||
class OutputFile(object):
|
||||
def __init__(self, output_zip, input_dir, prefix, name):
|
||||
|
@ -94,7 +96,6 @@ class OutputFile(object):
|
|||
if self._output_zip:
|
||||
common.ZipWrite(self._output_zip, self.name, self._zip_name)
|
||||
|
||||
|
||||
def GetCareMap(which, imgname):
|
||||
"""Returns the care_map string for the given partition.
|
||||
|
||||
|
@ -259,11 +260,7 @@ def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
|
|||
if fstab and mount_point in fstab:
|
||||
image_props["fs_type"] = fstab[mount_point].fs_type
|
||||
|
||||
# Use a fixed timestamp (01/01/2009) when packaging the image.
|
||||
# Bug: 24377993
|
||||
epoch = datetime.datetime.fromtimestamp(0)
|
||||
timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
|
||||
image_props["timestamp"] = int(timestamp)
|
||||
image_props["timestamp"] = FIXED_FILE_TIMESTAMP
|
||||
|
||||
if what == "system":
|
||||
fs_config_prefix = ""
|
||||
|
@ -337,11 +334,7 @@ def AddUserdata(output_zip):
|
|||
|
||||
print("creating userdata.img...")
|
||||
|
||||
# Use a fixed timestamp (01/01/2009) when packaging the image.
|
||||
# Bug: 24377993
|
||||
epoch = datetime.datetime.fromtimestamp(0)
|
||||
timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
|
||||
image_props["timestamp"] = int(timestamp)
|
||||
image_props["timestamp"] = FIXED_FILE_TIMESTAMP
|
||||
|
||||
if OPTIONS.info_dict.get("userdata_img_with_data") == "true":
|
||||
user_dir = os.path.join(OPTIONS.input_tmp, "DATA")
|
||||
|
@ -483,11 +476,7 @@ def AddCache(output_zip):
|
|||
|
||||
print("creating cache.img...")
|
||||
|
||||
# Use a fixed timestamp (01/01/2009) when packaging the image.
|
||||
# Bug: 24377993
|
||||
epoch = datetime.datetime.fromtimestamp(0)
|
||||
timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
|
||||
image_props["timestamp"] = int(timestamp)
|
||||
image_props["timestamp"] = FIXED_FILE_TIMESTAMP
|
||||
|
||||
user_dir = common.MakeTempDir()
|
||||
|
||||
|
|
|
@ -1271,8 +1271,12 @@ def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
|
|||
os.chmod(filename, perms)
|
||||
|
||||
# Use a fixed timestamp so the output is repeatable.
|
||||
epoch = datetime.datetime.fromtimestamp(0)
|
||||
timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
|
||||
# Note: Use of fromtimestamp rather than utcfromtimestamp here is
|
||||
# intentional. zip stores datetimes in local time without a time zone
|
||||
# attached, so we need "epoch" but in the local time zone to get 2009/01/01
|
||||
# in the zip archive.
|
||||
local_epoch = datetime.datetime.fromtimestamp(0)
|
||||
timestamp = (datetime.datetime(2009, 1, 1) - local_epoch).total_seconds()
|
||||
os.utime(filename, (timestamp, timestamp))
|
||||
|
||||
zip_file.write(filename, arcname=arcname, compress_type=compress_type)
|
||||
|
|
Loading…
Reference in a new issue