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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user