mirror of
https://github.com/esphome/esphome.git
synced 2025-11-01 07:31:51 +00:00
wip
This commit is contained in:
@@ -89,7 +89,7 @@ class GitHubCache:
|
|||||||
etag: ETag header from previous response
|
etag: ETag header from previous response
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if modified (or unable to check), False if not modified
|
True if modified, False if not modified (or offline/unreachable)
|
||||||
"""
|
"""
|
||||||
if not last_modified and not etag:
|
if not last_modified and not etag:
|
||||||
# No cache headers available, assume modified
|
# No cache headers available, assume modified
|
||||||
@@ -115,9 +115,9 @@ class GitHubCache:
|
|||||||
return False
|
return False
|
||||||
# Other errors, assume modified to be safe
|
# Other errors, assume modified to be safe
|
||||||
return True
|
return True
|
||||||
except (OSError, urllib.error.URLError) as e:
|
except (OSError, urllib.error.URLError):
|
||||||
# If check fails, assume not modified (use cache)
|
# If check fails (offline/network error), assume not modified (use cache)
|
||||||
_LOGGER.debug("Failed to check if modified: %s", e)
|
_LOGGER.info("Cannot reach server (offline?), using cached file: %s", url)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_cached_path(self, url: str, check_updates: bool = True) -> Path | None:
|
def get_cached_path(self, url: str, check_updates: bool = True) -> Path | None:
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ def patch_file_downloader():
|
|||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
self._destination = join(dest_dir, self._fname)
|
self._destination = join(dest_dir, self._fname)
|
||||||
_LOGGER.info("Using cached download for %s", url)
|
# Note: Actual restoration logged in patched_start
|
||||||
return None # Don't call original_init
|
return None # Don't call original_init
|
||||||
|
|
||||||
# Normal initialization with retry logic
|
# Normal initialization with retry logic
|
||||||
@@ -132,6 +132,9 @@ def patch_file_downloader():
|
|||||||
if cached_file:
|
if cached_file:
|
||||||
try:
|
try:
|
||||||
shutil.copy2(cached_file, self._destination)
|
shutil.copy2(cached_file, self._destination)
|
||||||
|
_LOGGER.info(
|
||||||
|
"Restored %s from cache (avoided download)", Path(cached_file).name
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
_LOGGER.warning("Failed to copy from cache: %s", e)
|
_LOGGER.warning("Failed to copy from cache: %s", e)
|
||||||
|
|||||||
Reference in New Issue
Block a user