From 203c9a779971996af753a8e1f983b6def9094b68 Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Mon, 15 Dec 2025 23:02:50 +0100 Subject: [PATCH] Set file timestamp from mirror source The create-python-mirror.py script will now set the timestamp of the downloaded files. --- scripts/create-python-mirror.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/create-python-mirror.py b/scripts/create-python-mirror.py index 375dce976..ffe5fc2de 100644 --- a/scripts/create-python-mirror.py +++ b/scripts/create-python-mirror.py @@ -15,9 +15,11 @@ Example usage: import argparse import asyncio +import datetime import hashlib import json import logging +import os import re from pathlib import Path from typing import Dict, List, Optional, Set, Tuple @@ -171,6 +173,14 @@ async def download_file( with open(dest, "wb") as f: async for chunk in response.aiter_bytes(): f.write(chunk) + last_modified = response.headers.get("Last-Modified") + if last_modified is not None: + last_modified = datetime.datetime.strptime( + last_modified, "%a, %d %b %Y %H:%M:%S %Z" + ) + if last_modified is not None: + file_time = last_modified.timestamp() + os.utime(dest, (file_time, file_time)) if expected_sha256 and sha256_checksum(dest) != expected_sha256: error_msg = f"SHA-256 mismatch for {dest}. Deleting corrupted file."