Files
dragonpilot/selfdrive/loggerd/xattr_cache.py
Dragonpilot Team 32da3d10c7 dragonpilot v2022.08.14
version: dragonpilot v0.8.16 release
date: 2022-08-14T16:03:36
dp-dev(priv) master commit: 9a40536565e6da64122ef8c30d7e97523fde518e
2022-08-14 16:03:47 -07:00

24 lines
696 B
Python

import os
import errno
from typing import Dict, Tuple, Optional
_cached_attributes: Dict[Tuple, Optional[bytes]] = {}
def getxattr(path: str, attr_name: str) -> Optional[bytes]:
key = (path, attr_name)
if key not in _cached_attributes:
try:
response = os.getxattr(path, attr_name)
except OSError as e:
# ENODATA means attribute hasn't been set
if e.errno == errno.ENODATA:
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)
return os.setxattr(path, attr_name, attr_value)