mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 06:33:57 +08:00
* Mypy: Got passing on macos (#34591) * Mypy: Got mypy passing on macos * common/realtime.py refactor * Mypy: mypy passing on darwin * Refactor: Removed else: pass statement * Refactor: Removed unnecessary check * added xattr to pyproject * loggerd: switched to xatter module * loggerd: removed unused module in xattr_cache.py * UV: update uv.lock * Update system/athena/athenad.py * athenad: fixed blank lines * loggerd: refactor of xattr_cache * cleanup --------- * fix getxattr no attribute on macOS * try fixing missing ENOATTR on Linux --------- Co-authored-by: Andrei Radulescu <andi.radulescu@gmail.com> Co-authored-by: BrainLess <116778989+BrainLessPea@users.noreply.github.com>
24 lines
739 B
Python
24 lines
739 B
Python
import errno
|
|
|
|
import xattr
|
|
|
|
_cached_attributes: dict[tuple, bytes | None] = {}
|
|
|
|
def getxattr(path: str, attr_name: str) -> bytes | None:
|
|
key = (path, attr_name)
|
|
if key not in _cached_attributes:
|
|
try:
|
|
response = xattr.getxattr(path, attr_name)
|
|
except OSError as e:
|
|
# ENODATA (Linux) or ENOATTR (macOS) means attribute hasn't been set
|
|
if e.errno == errno.ENODATA or (hasattr(errno, 'ENOATTR') and e.errno == errno.ENOATTR):
|
|
response = None
|
|
else:
|
|
raise
|
|
_cached_attributes[key] = response
|
|
return _cached_attributes[key]
|
|
|
|
def setxattr(path: str, attr_name: str, attr_value: bytes) -> None:
|
|
_cached_attributes.pop((path, attr_name), None)
|
|
xattr.setxattr(path, attr_name, attr_value)
|