mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-23 12:12:06 +08:00
@@ -1,6 +1,53 @@
|
||||
import ctypes
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
|
||||
import xattr
|
||||
|
||||
if sys.platform == "darwin":
|
||||
_libc = ctypes.CDLL(None, use_errno=True)
|
||||
_libc.getxattr.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_int]
|
||||
_libc.getxattr.restype = ctypes.c_ssize_t
|
||||
_libc.setxattr.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_int]
|
||||
_libc.setxattr.restype = ctypes.c_int
|
||||
|
||||
|
||||
def _raise_os_error(path: str) -> None:
|
||||
error = ctypes.get_errno()
|
||||
raise OSError(error, os.strerror(error), path)
|
||||
|
||||
|
||||
def _getxattr(path: str, attr_name: str) -> bytes:
|
||||
if sys.platform != "darwin":
|
||||
return os.getxattr(path, attr_name)
|
||||
|
||||
encoded_path = os.fsencode(path)
|
||||
encoded_attr_name = os.fsencode(attr_name)
|
||||
while True:
|
||||
size = _libc.getxattr(encoded_path, encoded_attr_name, None, 0, 0, 0)
|
||||
if size == -1:
|
||||
_raise_os_error(path)
|
||||
if size == 0:
|
||||
return b""
|
||||
|
||||
value = ctypes.create_string_buffer(size)
|
||||
result = _libc.getxattr(encoded_path, encoded_attr_name, value, size, 0, 0)
|
||||
if result != -1:
|
||||
return value.raw[:result]
|
||||
if ctypes.get_errno() != errno.ERANGE:
|
||||
_raise_os_error(path)
|
||||
|
||||
|
||||
def _setxattr(path: str, attr_name: str, attr_value: bytes) -> None:
|
||||
if sys.platform != "darwin":
|
||||
os.setxattr(path, attr_name, attr_value)
|
||||
return
|
||||
|
||||
encoded_path = os.fsencode(path)
|
||||
encoded_attr_name = os.fsencode(attr_name)
|
||||
value = ctypes.create_string_buffer(attr_value)
|
||||
if _libc.setxattr(encoded_path, encoded_attr_name, value, len(attr_value), 0, 0) == -1:
|
||||
_raise_os_error(path)
|
||||
|
||||
_cached_attributes: dict[tuple, bytes | None] = {}
|
||||
|
||||
@@ -8,7 +55,7 @@ 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)
|
||||
response = _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):
|
||||
@@ -20,4 +67,4 @@ def getxattr(path: str, attr_name: str) -> bytes | None:
|
||||
|
||||
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)
|
||||
_setxattr(path, attr_name, attr_value)
|
||||
|
||||
@@ -40,7 +40,6 @@ dependencies = [
|
||||
# logging
|
||||
"pyzmq",
|
||||
"sentry-sdk",
|
||||
"xattr", # used in place of 'os.getxattr' for macOS compatibility
|
||||
|
||||
# athena
|
||||
"PyJWT[crypto]",
|
||||
|
||||
@@ -734,7 +734,6 @@ dependencies = [
|
||||
{ name = "sounddevice" },
|
||||
{ name = "tqdm" },
|
||||
{ name = "websocket-client" },
|
||||
{ name = "xattr" },
|
||||
{ name = "zstandard" },
|
||||
]
|
||||
|
||||
@@ -830,7 +829,6 @@ requires-dist = [
|
||||
{ name = "tqdm" },
|
||||
{ name = "ty", marker = "extra == 'testing'" },
|
||||
{ name = "websocket-client" },
|
||||
{ name = "xattr" },
|
||||
{ name = "zensical", marker = "extra == 'docs'" },
|
||||
{ name = "zstandard" },
|
||||
]
|
||||
@@ -1466,24 +1464,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/34/db/b10e48aa8fff7407e67470363eac595018441cf32d5e1001567a7aeba5d2/websocket_client-1.9.0-py3-none-any.whl", hash = "sha256:af248a825037ef591efbf6ed20cc5faa03d3b47b9e5a2230a529eeee1c1fc3ef", size = 82616, upload-time = "2025-10-07T21:16:34.951Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xattr"
|
||||
version = "1.3.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "cffi" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/08/d5/25f7b19af3a2cb4000cac4f9e5525a40bec79f4f5d0ac9b517c0544586a0/xattr-1.3.0.tar.gz", hash = "sha256:30439fabd7de0787b27e9a6e1d569c5959854cb322f64ce7380fedbfa5035036", size = 17148, upload-time = "2025-10-13T22:16:47.353Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/bf/78/00bdc9290066173e53e1e734d8d8e1a84a6faa9c66aee9df81e4d9aeec1c/xattr-1.3.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:dd4e63614722d183e81842cb237fd1cc978d43384166f9fe22368bfcb187ebe5", size = 23476, upload-time = "2025-10-13T22:16:06.942Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/53/16/5243722294eb982514fa7b6b87a29dfb7b29b8e5e1486500c5babaf6e4b3/xattr-1.3.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:995843ef374af73e3370b0c107319611f3cdcdb6d151d629449efecad36be4c4", size = 18556, upload-time = "2025-10-13T22:16:08.209Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d6/5c/d7ab0e547bea885b55f097206459bd612cefb652c5fc1f747130cbc0d42c/xattr-1.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fa23a25220e29d956cedf75746e3df6cc824cc1553326d6516479967c540e386", size = 18869, upload-time = "2025-10-13T22:16:10.319Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/98/25/25cc7d64f07de644b7e9057842227adf61017e5bcfe59a79df79f768874c/xattr-1.3.0-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:b4345387087fffcd28f709eb45aae113d911e1a1f4f0f70d46b43ba81e69ccdd", size = 38797, upload-time = "2025-10-13T22:16:11.624Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a9/24/cc350bcdbed006dfcc6ade0ac817693b8b3d4b2787f20e427fd0697042e4/xattr-1.3.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:fe92bb05eb849ab468fe13e942be0f8d7123f15d074f3aba5223fad0c4b484de", size = 38956, upload-time = "2025-10-13T22:16:13.121Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9b/b2/9416317ac89e2ed759a861857cda0d5e284c3691e6f460d36cc2bd5ce4d1/xattr-1.3.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6c42ef5bdac3febbe28d3db14d3a8a159d84ba5daca2b13deae6f9f1fc0d4092", size = 38214, upload-time = "2025-10-13T22:16:14.389Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/38/63/188f7cb41ab35d795558325d5cc8ab552171d5498cfb178fd14409651e18/xattr-1.3.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:2aaa5d66af6523332189108f34e966ca120ff816dfa077ca34b31e6263f8a236", size = 37754, upload-time = "2025-10-13T22:16:15.306Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zensical"
|
||||
version = "0.0.46"
|
||||
|
||||
Reference in New Issue
Block a user