Beispiel #1
0
def _copyxattr(src, dest, exclude=None):
	"""Copy the extended attributes from |src| to |dest|"""
	try:
		attrs = xattr.list(src)
	except (OSError, IOError) as e:
		if e.errno != OperationNotSupported.errno:
			raise
		attrs = ()

	if attrs:
		if exclude is not None and isinstance(attrs[0], bytes):
			exclude = exclude.encode(_encodings['fs'])
		exclude = _get_xattr_excluder(exclude)

	for attr in attrs:
		if exclude(attr):
			continue
		try:
			xattr.set(dest, attr, xattr.get(src, attr))
			raise_exception = False
		except (OSError, IOError):
			raise_exception = True
		if raise_exception:
			raise OperationNotSupported(_("Filesystem containing file '%s' "
				"does not support extended attribute '%s'") %
				(_unicode_decode(dest), _unicode_decode(attr)))
Beispiel #2
0
def _copyxattr(src, dest, exclude=None):
	"""Copy the extended attributes from |src| to |dest|"""
	try:
		attrs = xattr.list(src)
	except (OSError, IOError) as e:
		if e.errno != OperationNotSupported.errno:
			raise
		attrs = ()

	if attrs:
		if exclude is not None and isinstance(attrs[0], bytes):
			exclude = exclude.encode(_encodings['fs'])
		exclude = _get_xattr_excluder(exclude)

	for attr in attrs:
		if exclude(attr):
			continue
		try:
			xattr.set(dest, attr, xattr.get(src, attr))
			raise_exception = False
		except (OSError, IOError):
			raise_exception = True
		if raise_exception:
			raise OperationNotSupported(_("Filesystem containing file '%s' "
				"does not support extended attribute '%s'") %
				(_unicode_decode(dest), _unicode_decode(attr)))
Beispiel #3
0
 def __get(self, path, key, default=None):
     try:
         return xattr.get(path, key, namespace=self.ns)
     except IOError as e:
         if not default is None and errno.ENODATA == e.errno:
             return default
         raise NoValueException()
Beispiel #4
0
def dump_xattrs(pathnames, file_out):
    """Dump the xattr data for |pathnames| to |file_out|"""
    # NOTE: Always quote backslashes, in order to ensure that they are
    # not interpreted as quotes when they are processed by unquote.
    quote_chars = b'\n\r\\\\'

    for pathname in pathnames:
        attrs = xattr.list(pathname)
        if not attrs:
            continue

        file_out.write(b'# file: %s\n' % quote(pathname, quote_chars))
        for attr in attrs:
            attr = unicode_encode(attr)
            value = xattr.get(pathname, attr)
            file_out.write(b'%s="%s"\n' % (quote(
                attr, b'=' + quote_chars), quote(value, b'\0"' + quote_chars)))
Beispiel #5
0
def dump_xattrs(pathnames, file_out):
	"""Dump the xattr data for |pathnames| to |file_out|"""
	# NOTE: Always quote backslashes, in order to ensure that they are
	# not interpreted as quotes when they are processed by unquote.
	quote_chars = b'\n\r\\\\'

	for pathname in pathnames:
		attrs = xattr.list(pathname)
		if not attrs:
			continue

		file_out.write(b'# file: %s\n' % quote(pathname, quote_chars))
		for attr in attrs:
			attr = unicode_encode(attr)
			value = xattr.get(pathname, attr)
			file_out.write(b'%s="%s"\n' % (
				quote(attr, b'=' + quote_chars),
				quote(value, b'\0"' + quote_chars)))