Skip to content

Commit ab2a21f

Browse files
committed
tc
1 parent 501b943 commit ab2a21f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

s3_management/manage.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,7 @@ def to_simple_package_html(
382382
out.append(' <body>')
383383
out.append(' <h1>Links for {}</h1>'.format(package_name.lower().replace("_", "-")))
384384
for obj in sorted(self.gen_file_list(subdir, package_name)):
385-
386385
maybe_fragment = f"#sha256={obj.checksum}" if obj.checksum else ""
387-
388-
# Temporary skip assigning sha256 to nightly index
389-
# to be reverted on Jan 24, 2025.
390-
if subdir is not None and "nightly" in subdir:
391-
maybe_fragment = ""
392-
393386
pep658_attribute = ""
394387
if obj.pep658:
395388
pep658_sha = f"sha256={obj.pep658}"
@@ -528,6 +521,7 @@ def fetch_object_names(cls: Type[S3IndexType], prefix: str) -> List[str]:
528521

529522
def fetch_metadata(self: S3IndexType) -> None:
530523
# Add PEP 503-compatible hashes to URLs to allow clients to avoid spurious downloads, if possible.
524+
regex_multipart_upload = r"^[A-Za-z0-9+/=]+=-[0-9]+$"
531525
with concurrent.futures.ThreadPoolExecutor(max_workers=6) as executor:
532526
for idx, future in {
533527
idx: executor.submit(
@@ -540,10 +534,17 @@ def fetch_metadata(self: S3IndexType) -> None:
540534
if obj.size is None
541535
}.items():
542536
response = future.result()
543-
sha256 = (_b64 := response.get("ChecksumSHA256")) and base64.b64decode(_b64).hex()
537+
raw = response.get("ChecksumSHA256")
538+
if raw and match(regex_multipart_upload, raw):
539+
# Possibly part of a multipart upload, making the checksum incorrect
540+
print(f"WARNING: {self.objects[idx].orig_key} has bad checksum: {raw}")
541+
raw = None
542+
sha256 = raw and base64.b64decode(raw).hex()
544543
# For older files, rely on checksum-sha256 metadata that can be added to the file later
545544
if sha256 is None:
546545
sha256 = response.get("Metadata", {}).get("checksum-sha256")
546+
if sha256 is None:
547+
sha256 = response.get("Metadata", {}).get("x-amz-meta-checksum-sha256")
547548
self.objects[idx].checksum = sha256
548549
if size := response.get("ContentLength"):
549550
self.objects[idx].size = int(size)

0 commit comments

Comments
 (0)