|
@@ -282,13 +282,13 @@ def package_base(output: Path) -> Path:
|
|
|
payload = common_payload("base", commit, tree, selected, {"base_id": base_id,
|
|
payload = common_payload("base", commit, tree, selected, {"base_id": base_id,
|
|
|
"base_manifest_sha256": sha_bytes(base_manifest)})
|
|
"base_manifest_sha256": sha_bytes(base_manifest)})
|
|
|
target = output / f"Prod2U-CPLD-Analysis-Base-{base_id}.zip"
|
|
target = output / f"Prod2U-CPLD-Analysis-Base-{base_id}.zip"
|
|
|
|
|
+ if target.exists():
|
|
|
|
|
+ existing_id, _existing_manifest, existing_base_manifest_sha = base_metadata(target)
|
|
|
|
|
+ if existing_id != base_id or existing_base_manifest_sha != sha_bytes(base_manifest):
|
|
|
|
|
+ raise SystemExit("BASE_ID_COLLISION")
|
|
|
|
|
+ return target
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
|
candidate = write_zip(Path(tmp) / target.name, payload)
|
|
candidate = write_zip(Path(tmp) / target.name, payload)
|
|
|
- if target.exists():
|
|
|
|
|
- verify_zip(target)
|
|
|
|
|
- if sha_file(target) != sha_file(candidate):
|
|
|
|
|
- raise SystemExit("BASE_ID_COLLISION")
|
|
|
|
|
- return target
|
|
|
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
|
shutil.copy2(candidate, target)
|
|
shutil.copy2(candidate, target)
|
|
|
return target
|
|
return target
|
|
@@ -296,10 +296,13 @@ def package_base(output: Path) -> Path:
|
|
|
|
|
|
|
|
def base_metadata(base_zip: Path) -> tuple[str, dict, str]:
|
|
def base_metadata(base_zip: Path) -> tuple[str, dict, str]:
|
|
|
verify_zip(base_zip)
|
|
verify_zip(base_zip)
|
|
|
- with zipfile.ZipFile(base_zip) as archive:
|
|
|
|
|
- manifest = json.loads(archive.read("PACKAGE-MANIFEST.json"))
|
|
|
|
|
- identity = json.loads(archive.read("BASE-IDENTITY.json"))
|
|
|
|
|
- base_manifest_bytes = archive.read("BASE-PACKAGE-MANIFEST.json")
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ with zipfile.ZipFile(base_zip) as archive:
|
|
|
|
|
+ manifest = json.loads(archive.read("PACKAGE-MANIFEST.json"))
|
|
|
|
|
+ identity = json.loads(archive.read("BASE-IDENTITY.json"))
|
|
|
|
|
+ base_manifest_bytes = archive.read("BASE-PACKAGE-MANIFEST.json")
|
|
|
|
|
+ except (KeyError, json.JSONDecodeError) as exc:
|
|
|
|
|
+ raise SystemExit("BASE_IDENTITY_INVALID") from exc
|
|
|
if manifest.get("profile") != "base":
|
|
if manifest.get("profile") != "base":
|
|
|
raise SystemExit("selected Base package is not profile=base")
|
|
raise SystemExit("selected Base package is not profile=base")
|
|
|
if identity.get("base_id") != manifest.get("base_id"):
|
|
if identity.get("base_id") != manifest.get("base_id"):
|