未验证 提交 1233be88 编写于 作者: F Frost Ming 提交者: GitHub

fix: suppress errors when cache dir isn't accessible (#1229)

上级 e5702462
Suppress errors when cache dir isn't accessible.
from __future__ import annotations
import contextlib
import datetime
import hashlib
import json
......@@ -839,10 +840,9 @@ def get_latest_version(project: Project) -> str | None:
"""Get the latest version of PDM from PyPI, cache for 7 days"""
cache_key = hashlib.sha224(sys.executable.encode()).hexdigest()
cache_file = project.cache("self-check") / cache_key
if cache_file.exists():
state = {}
with contextlib.suppress(OSError):
state = json.loads(cache_file.read_text())
else:
state = {}
current_time = datetime.datetime.utcnow().timestamp()
if (
state.get("last-check")
......@@ -857,7 +857,8 @@ def get_latest_version(project: Project) -> str | None:
return None
latest_version = str(candidate.version)
state.update({"latest-version": latest_version, "last-check": current_time})
cache_file.write_text(json.dumps(state))
with contextlib.suppress(OSError):
cache_file.write_text(json.dumps(state))
return latest_version
......
......@@ -644,7 +644,11 @@ dependencies = ["pip", "setuptools", "wheel"]
def cache(self, name: str) -> Path:
path = self.cache_dir / name
path.mkdir(parents=True, exist_ok=True)
try:
path.mkdir(parents=True, exist_ok=True)
except OSError:
# The path could be not accessible
pass
return path
def make_wheel_cache(self) -> WheelCache:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册