Remove ETag from cache if response didn't provide it

This commit is contained in:
monosans
2024-02-18 12:11:04 +03:00
parent 39e40af559
commit 32fd6158ec
+7
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
import logging
import stat
from typing import Optional
@@ -28,6 +29,10 @@ async def _read_etag() -> Optional[str]:
return bytes_decode(content)
def _remove_etag() -> asyncio.Future[None]:
return asyncify(GEODB_ETAG_PATH.unlink)(missing_ok=True)
async def _save_etag(etag: str, /) -> None:
await fs.async_add_permission(
GEODB_ETAG_PATH, stat.S_IWUSR, missing_ok=True
@@ -85,3 +90,5 @@ async def download_geodb(*, progress: Progress, session: ClientSession) -> None:
if etag := response.headers.get(hdrs.ETAG):
await _save_etag(etag)
else:
await _remove_etag()