Improve SHA256 checksum parsing for Deno
Enhances the verify_deno_sha256 function to support both standard Unix and verbose checksum file formats. Adds debug logging for cases where the hash cannot be found.
This commit is contained in:
+18
-5
@@ -52,14 +52,26 @@ def verify_deno_sha256(file_path: Path, sha256_url: str) -> bool:
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
checksum_content = response.text
|
checksum_content = response.text
|
||||||
|
|
||||||
# Parse the checksum file - format is:
|
# Parse the checksum file
|
||||||
# Algorithm : SHA256
|
# Format can be either:
|
||||||
# Hash : <HASH>
|
# 1. Standard Unix format: "hash filename"
|
||||||
# Path : <PATH>
|
# 2. Verbose format: "Hash : <HASH>"
|
||||||
expected_hash = None
|
expected_hash = None
|
||||||
for line in checksum_content.strip().split("\n"):
|
for line in checksum_content.strip().split("\n"):
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Try standard Unix format first (hash followed by spaces and filename)
|
||||||
|
if len(line) >= 64 and (" " in line or "\t" in line):
|
||||||
|
# Extract first 64 characters as potential hash
|
||||||
|
potential_hash = line.split()[0]
|
||||||
|
if len(potential_hash) == 64 and all(c in "0123456789abcdefABCDEF" for c in potential_hash):
|
||||||
|
expected_hash = potential_hash
|
||||||
|
break
|
||||||
|
|
||||||
|
# Try verbose format
|
||||||
if line.startswith("Hash"):
|
if line.startswith("Hash"):
|
||||||
# Extract hash from "Hash : <HASH>" format
|
|
||||||
parts = line.split(":", 1)
|
parts = line.split(":", 1)
|
||||||
if len(parts) == 2:
|
if len(parts) == 2:
|
||||||
expected_hash = parts[1].strip()
|
expected_hash = parts[1].strip()
|
||||||
@@ -67,6 +79,7 @@ def verify_deno_sha256(file_path: Path, sha256_url: str) -> bool:
|
|||||||
|
|
||||||
if not expected_hash:
|
if not expected_hash:
|
||||||
logger.error("Could not find SHA256 hash in checksum file")
|
logger.error("Could not find SHA256 hash in checksum file")
|
||||||
|
logger.debug(f"Checksum file content: {checksum_content}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Calculate actual hash of downloaded file
|
# Calculate actual hash of downloaded file
|
||||||
|
|||||||
Reference in New Issue
Block a user