mirror of
https://github.com/qemu/qemu.git
synced 2026-11-06 20:04:47 +00:00
Assets cached before the stamp files were introduced have no corresponding .stamp file. The script already copes with that when reading the timestamp, by assuming the QEMU v10.1 release date, which makes such assets eligible for removal. However, since commitc1bb594fe4, removing the asset also unconditionally unlinks its .stamp file. For these old entries that file does not exist, so unlink() raises FileNotFoundError and the script aborts after deleting the first such asset, leaving the rest of the cache uncleaned and returning an error. Pass missing_ok=True so that a missing .stamp file is not an error. Fixes:c1bb594fe4("scripts/clean_functional_cache: Remove also .stamp files") Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
48 lines
1.3 KiB
Python
Executable File
48 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
#
|
|
"""Delete stale assets from the download cache of the functional tests"""
|
|
|
|
import os
|
|
import stat
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
|
|
cache_dir_env = os.getenv('QEMU_TEST_CACHE_DIR')
|
|
if cache_dir_env:
|
|
cache_dir = Path(cache_dir_env, "download")
|
|
else:
|
|
cache_dir = Path(Path("~").expanduser(), ".cache", "qemu", "download")
|
|
|
|
if not cache_dir.exists():
|
|
print(f"Cache dir {cache_dir} does not exist!", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
os.chdir(cache_dir)
|
|
|
|
for file in cache_dir.iterdir():
|
|
# Only consider the files that use a sha256 as filename:
|
|
if len(file.name) != 64:
|
|
continue
|
|
|
|
stampfile = file.with_suffix(".stamp")
|
|
try:
|
|
timestamp = int(stampfile.read_text())
|
|
except FileNotFoundError:
|
|
# Assume it's an old file that was already in the cache before we
|
|
# added the code for evicting stale assets. Use the release date
|
|
# of QEMU v10.1 as a default timestamp.
|
|
timestamp = time.mktime((2025, 8, 26, 0, 0, 0, 0, 0, 0))
|
|
|
|
age = time.time() - timestamp
|
|
|
|
# Delete files older than half of a year (183 days * 24h * 60m * 60s)
|
|
if age > 15811200:
|
|
print(f"Removing {cache_dir}/{file.name}.")
|
|
file.chmod(stat.S_IWRITE)
|
|
file.unlink()
|
|
stampfile.unlink(missing_ok=True)
|