mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-08 22:42:05 +08:00
4d7a40310f
version: dragonpilot v0.8.16 beta for EON/C2 date: 2022-08-11T09:38:43 dp-dev(priv2) master commit: c6cd233f23f60e7a6055d42850bc593c0e69082e
26 lines
784 B
Python
26 lines
784 B
Python
# import os
|
|
import errno
|
|
from typing import Dict, Tuple, Optional
|
|
from common.xattr import getxattr as getattr1
|
|
from common.xattr import setxattr as setattr1
|
|
|
|
_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 = getattr1(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 setattr1(path, attr_name, attr_value)
|