def getxattr(self, path, xattr, position=0):
"""Called with a specific namespace.name xattr. Can return either
a bytes array OR an int."""
if position:
raise TmfsOSError(errno.ENOSYS) # never saw this in 8 months
rsp = self.librarian(self.lcp('get_shelf', path=path))
shelf = TMShelf(rsp)
# Does this also need changed to support path instead of name?
# Piggy back for queries by kernel (globals & fault handling).
if xattr.startswith('_obtain_'):
# this will need some work
data = self.shadow.getxattr(shelf, xattr)
try:
return bytes(data.encode())
except AttributeError as e: # probably the "encode()"
self._ret_is_string = False
return bytes(data)
# "ls" starts with simple getattr but then comes here for
# security.selinux, system.posix_acl_access, and posix_acl_default.
# ls -l can also do the same thing on '/'. Save the round trips.
# if xattr.startswith('security.') or not shelf_name: # path == '/'
if xattr.startswith('security.'): # path == '/' is legal now
return bytes(0)
try:
rsp = self.librarian(
self.lcp('get_xattr', path=path, xattr=xattr))
value = rsp['value']
assert value is not None # 'No such attribute'
if isinstance(value, int):
return value
elif isinstance(value, str):
# http://stackoverflow.com/questions/606191/convert-bytes-to-a-python-string
return bytes(value.encode('cp437'))
else:
bytes(value.encode())
except Exception as e:
raise TmfsOSError(errno.ENODATA) # syn for ENOATTR
评论列表
文章目录