From 80bc5833e7a7df4f9f258b19b38f67209b1d413e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 8 Dec 2023 14:44:39 -0800 Subject: [PATCH] remove common/xattr.py --- common/xattr.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 common/xattr.py diff --git a/common/xattr.py b/common/xattr.py deleted file mode 100644 index 26616fd638..0000000000 --- a/common/xattr.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -from cffi import FFI -from typing import Any, List - -# Workaround for the EON/termux build of Python having os.*xattr removed. -ffi = FFI() -ffi.cdef(""" -int setxattr(const char *path, const char *name, const void *value, size_t size, int flags); -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); -ssize_t listxattr(const char *path, char *list, size_t size); -int removexattr(const char *path, const char *name); -""") -libc = ffi.dlopen(None) - -def setxattr(path, name, value, flags=0) -> None: - path = path.encode() - name = name.encode() - if libc.setxattr(path, name, value, len(value), flags) == -1: - raise OSError(ffi.errno, f"{os.strerror(ffi.errno)}: setxattr({path}, {name}, {value}, {flags})") - -def getxattr(path, name, size=128): - path = path.encode() - name = name.encode() - value = ffi.new(f"char[{size}]") - l = libc.getxattr(path, name, value, size) - if l == -1: - # errno 61 means attribute hasn't been set - if ffi.errno == 61: - return None - raise OSError(ffi.errno, f"{os.strerror(ffi.errno)}: getxattr({path}, {name}, {size})") - return ffi.buffer(value)[:l] - -def listxattr(path, size=128) -> List[Any]: - path = path.encode() - attrs = ffi.new(f"char[{size}]") - l = libc.listxattr(path, attrs, size) - if l == -1: - raise OSError(ffi.errno, f"{os.strerror(ffi.errno)}: listxattr({path}, {size})") - # attrs is b'\0' delimited values (so chop off trailing empty item) - return [a.decode() for a in ffi.buffer(attrs)[:l].split(b"\0")[0:-1]] - -def removexattr(path, name) -> None: - path = path.encode() - name = name.encode() - if libc.removexattr(path, name) == -1: - raise OSError(ffi.errno, f"{os.strerror(ffi.errno)}: removexattr({path}, {name})")