44import json
55import logging
66import struct
7+ from dateutil import parser
8+ from datetime import datetime
79from os import getgid , getuid
810from pathlib import Path
911from re import match
@@ -433,6 +435,15 @@ def parse_kernel_version(url: str) -> str:
433435 return f"{ kernel_version } -{ kernel_release } -{ kernel_vermagic } "
434436 return ""
435437
438+ def is_fully_compiled_version (version : str ) -> bool :
439+ """Check that a given version is at least 48h old"""
440+ response = client_get (settings .upstream_url + "/releases/" + version + "/.targets.json" )
441+
442+ if response .extensions ["from_cache" ]:
443+ last_modified = int (parser .parse (response .headers ["Last-Modified" ]).timestamp ())
444+ if int (datetime .now ().timestamp ()) - last_modified < 172800 :
445+ return False
446+ return True
436447
437448def reload_versions (app : FastAPI ) -> bool :
438449 response = client_get (settings .upstream_url + "/.versions.json" )
@@ -451,6 +462,12 @@ def reload_versions(app: FastAPI) -> bool:
451462 if response .json ()["upcoming_version" ]:
452463 app .versions .append (response .json ()["upcoming_version" ])
453464
465+ # Avoid offering versions that are not yet fully compiled
466+ for label in ["stable_version" , "oldstable_version" , "upcoming_version" ]:
467+ version = response .json ()[label ]
468+ if version and not is_fully_compiled_version (version ):
469+ app .versions .remove (version )
470+
454471 for branch in settings .branches .keys ():
455472 if branch != "SNAPSHOT" :
456473 app .versions .append (f"{ branch } -SNAPSHOT" )
0 commit comments