Skip to content

Commit de4f37d

Browse files
committed
Recursively purge all download URLs
1 parent cb570fd commit de4f37d

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

run_release.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import contextlib
1212
import functools
1313
import getpass
14+
import http.client
1415
import json
1516
import os
1617
import re
@@ -942,22 +943,24 @@ def purge_the_cdn(db: ReleaseShelf) -> None:
942943
"https://www.python.org/downloads/windows/",
943944
"https://www.python.org/downloads/macos/",
944945
]
945-
# Purge the source URLs and their associated metadata files.
946-
source_urls = [
947-
f"https://www.python.org/ftp/python/{normalized_release}/Python-{db['release']}.tgz",
948-
f"https://www.python.org/ftp/python/{normalized_release}/Python-{db['release']}.tar.xz",
949-
]
950-
for source_url in source_urls:
951-
urls.extend(
952-
[
953-
f"{source_url}",
954-
f"{source_url}.asc",
955-
f"{source_url}.crt",
956-
f"{source_url}.sig",
957-
f"{source_url}.sigstore",
958-
f"{source_url}.spdx.json",
959-
]
960-
)
946+
947+
# Recursively discover artifacts to purge.
948+
ftp_download_pages = [f"https://www.python.org/ftp/python/{normalized_release}/"]
949+
while ftp_download_pages:
950+
ftp_download_page = ftp_download_pages.pop(0)
951+
req = urllib.request.Request(method="GET", url=ftp_download_page, headers=headers)
952+
resp = urllib.request.urlopen(req)
953+
if resp.code != 200:
954+
raise RuntimeError("Failed to purge the python.org/downloads CDN")
955+
for link in re.findall(r"<a href=\"([^\"]+)\">", resp.read().decode()):
956+
if link in ("../", "./"): # Special value, ignore it.
957+
continue
958+
959+
if link.endswith("/"): # Directory, recurse into it.
960+
ftp_download_pages.append(f"{ftp_download_page}{link}")
961+
962+
# We want to purge both directories and files.
963+
urls.append(f"{ftp_download_page}{link}")
961964

962965
for url in urls:
963966
req = urllib.request.Request(url=url, headers=headers, method="PURGE")

0 commit comments

Comments
 (0)