Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 3
0
def restore_xattrs(file_in):
    """Read |file_in| and restore xattrs content from it

	This expects textual data in the format written by dump_xattrs.
	"""
    pathname = None
    for i, line in enumerate(file_in):
        if line.startswith(b'# file: '):
            pathname = unquote(line.rstrip(b'\n')[8:])
        else:
            parts = line.split(b'=', 1)
            if len(parts) == 2:
                if pathname is None:
                    raise ValueError('line %d: missing pathname' % (i + 1, ))
                attr = unquote(parts[0])
                # strip trailing newline and quotes
                value = unquote(parts[1].rstrip(b'\n')[1:-1])
                xattr.set(pathname, attr, value)
            elif line.strip():
                raise ValueError('line %d: malformed entry' % (i + 1, ))
Ejemplo n.º 4
0
def restore_xattrs(file_in):
	"""Read |file_in| and restore xattrs content from it

	This expects textual data in the format written by dump_xattrs.
	"""
	pathname = None
	for i, line in enumerate(file_in):
		if line.startswith(b'# file: '):
			pathname = unquote(line.rstrip(b'\n')[8:])
		else:
			parts = line.split(b'=', 1)
			if len(parts) == 2:
				if pathname is None:
					raise ValueError('line %d: missing pathname' % (i + 1,))
				attr = unquote(parts[0])
				# strip trailing newline and quotes
				value = unquote(parts[1].rstrip(b'\n')[1:-1])
				xattr.set(pathname, attr, value)
			elif line.strip():
				raise ValueError('line %d: malformed entry' % (i + 1,))
Ejemplo n.º 5
0
 def __set(self, path, key, value):
     xattr.set(path, key, value, namespace=self.ns)