Skip to content

Commit

Permalink
postprocess: Workaround for Python timestamp mismatch
Browse files Browse the repository at this point in the history
Python mtime timestamp logic does not work well with ostree force 0
mtime.

Use a small script to post-process all compiled '.pyc' and force the
timestamp to 0.

See: ostreedev/ostree#1469

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
  • Loading branch information
travier and hroncok committed Apr 12, 2024
1 parent fd6487c commit d085e9f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,47 @@ chmod 755 /usr/libexec/fedora-silverblue-readonly-sysroot

# Enable the corresponding unit
systemctl enable fedora-silverblue-readonly-sysroot.service

###

# Workaround for Python timestamp mismatch
# See: https://github.com/ostreedev/ostree/issues/1469

echo '
import os
import re
MIN_MAGIC = 3390 # The first magic number supporting PEP 552
ZERO = bytes((0, 0, 0, 0))
def pyc_set_zero_mtime(pyc_path):
with open(pyc_path, "r+b") as f:
w = f.read(4)
if len(w) < 4:
return 0
magic = (w[0] + (w[1] << 8) + (w[2] << 16) + (w[3] << 24)) & 0xFFFF
if magic < MIN_MAGIC:
invalidation = ZERO
else:
invalidation = f.read(4)
if len(invalidation) < 4:
return 0
if invalidation == ZERO:
f.write(ZERO)
return 1
return 0
if __name__ == "__main__":
REGEX = re.compile(r".*/__pycache__/[^/]+\.cpython-.*(\.opt-1|\.opt-2)?\.pyc$")
count = 0
for root, dirs, files in os.walk("/usr"):
for file in files:
path = os.path.join(root, file)
if REGEX.match(path):
count += pyc_set_zero_mtime(path)
print(f"Processed {count} pyc files")
' | python

0 comments on commit d085e9f

Please sign in to comment.