From f2837542699e8576c7461e1f957579c2aba6e5d7 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sun, 27 Oct 2024 00:23:47 +0200 Subject: [PATCH] =?UTF-8?q?Rename=20destination=5Fmapping=20=E2=86=92=20de?= =?UTF-8?q?stination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conda_lock/lookup.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/conda_lock/lookup.py b/conda_lock/lookup.py index d032ee908..f55cc8a6d 100644 --- a/conda_lock/lookup.py +++ b/conda_lock/lookup.py @@ -142,19 +142,18 @@ def cached_download_file(url: str) -> bytes: def download_to_or_read_from_cache(url: str, cache: Path) -> bytes: - destination_mapping = cache / cached_filename_for_url(url) - destination_etag = destination_mapping.with_suffix(".etag") + destination = cache / cached_filename_for_url(url) + destination_etag = destination.with_suffix(".etag") request_headers = {} # Return the contents immediately if the file is fresh - if destination_mapping.is_file(): - mtime = destination_mapping.stat().st_mtime + if destination.is_file(): + mtime = destination.stat().st_mtime age = time.time() - mtime if age < DONT_CHECK_IF_NEWER_THAN_SECONDS: logger.debug( - f"Using cached mapping {destination_mapping} without " - f"checking for updates" + f"Using cached mapping {destination} without checking for updates" ) - return destination_mapping.read_bytes() + return destination.read_bytes() # Get the ETag from the last download, if it exists if destination_etag.is_file(): old_etag = destination_etag.read_text().strip() @@ -163,19 +162,16 @@ def download_to_or_read_from_cache(url: str, cache: Path) -> bytes: logger.debug(f"Requesting {url}") res = requests.get(url, headers=request_headers) if res.status_code == 304: - logger.debug( - f"{url} has not changed since last download, " - f"using {destination_mapping}" - ) + logger.debug(f"{url} has not changed since last download, using {destination}") else: res.raise_for_status() - destination_mapping.write_bytes(res.content) + destination.write_bytes(res.content) if "ETag" in res.headers: destination_etag.write_text(res.headers["ETag"]) else: logger.warning("No ETag in response headers") - logger.debug(f"Downloaded {url} to {destination_mapping}") - return destination_mapping.read_bytes() + logger.debug(f"Downloaded {url} to {destination}") + return destination.read_bytes() def cached_filename_for_url(url: str) -> str: