summaryrefslogtreecommitdiff
path: root/rdiff-backup/rdiff_backup/eas_acls.py
diff options
context:
space:
mode:
Diffstat (limited to 'rdiff-backup/rdiff_backup/eas_acls.py')
-rw-r--r--rdiff-backup/rdiff_backup/eas_acls.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/rdiff-backup/rdiff_backup/eas_acls.py b/rdiff-backup/rdiff_backup/eas_acls.py
index da01051..817a052 100644
--- a/rdiff-backup/rdiff_backup/eas_acls.py
+++ b/rdiff-backup/rdiff_backup/eas_acls.py
@@ -57,7 +57,8 @@ class ExtendedAttributes:
def read_from_rp(self, rp):
"""Set the extended attributes from an rpath"""
try:
- attr_list = rp.conn.xattr.listxattr(rp.path, rp.issym())
+ attr_list = rp.conn.xattr.listxattr(rp.path.encode('utf-8'),
+ rp.issym())
except IOError, exc:
if exc[0] in (errno.EOPNOTSUPP, errno.EPERM, errno.ETXTBSY):
return # if not supported, consider empty
@@ -74,7 +75,8 @@ class ExtendedAttributes:
continue
try:
self.attr_dict[attr] = \
- rp.conn.xattr.getxattr(rp.path, attr, rp.issym())
+ rp.conn.xattr.getxattr(rp.path.encode('utf-8'),
+ attr, rp.issym())
except IOError, exc:
# File probably modified while reading, just continue
if exc[0] == errno.ENODATA: continue
@@ -86,9 +88,11 @@ class ExtendedAttributes:
def clear_rp(self, rp):
"""Delete all the extended attributes in rpath"""
try:
- for name in rp.conn.xattr.listxattr(rp.path, rp.issym()):
+ for name in rp.conn.xattr.listxattr(rp.path.encode('utf-8'),
+ rp.issym()):
try:
- rp.conn.xattr.removexattr(rp.path, name, rp.issym())
+ rp.conn.xattr.removexattr(rp.path.encode('utf-8'),
+ name, rp.issym())
except IOError, exc:
# SELinux attributes cannot be removed, and we don't want
# to bail out or be too noisy at low log levels.
@@ -111,7 +115,8 @@ class ExtendedAttributes:
self.clear_rp(rp)
for (name, value) in self.attr_dict.iteritems():
try:
- rp.conn.xattr.setxattr(rp.path, name, value, 0, rp.issym())
+ rp.conn.xattr.setxattr(rp.path.encode('utf-8'), name,
+ value, 0, rp.issym())
except IOError, exc:
# Mac and Linux attributes have different namespaces, so
# fail gracefully if can't call setxattr
@@ -149,13 +154,14 @@ def ea_compare_rps(rp1, rp2):
def EA2Record(ea):
"""Convert ExtendedAttributes object to text record"""
- str_list = ['# file: %s' % C.acl_quote(ea.get_indexpath())]
+ str_list = ['# file: %s' % C.acl_quote(ea.get_indexpath().encode('utf-8'))]
for (name, val) in ea.attr_dict.iteritems():
if not val: str_list.append(name)
else:
encoded_val = base64.encodestring(val).replace('\n', '')
try:
- str_list.append('%s=0s%s' % (C.acl_quote(name), encoded_val))
+ str_list.append('%s=0s%s' % (C.acl_quote(name.encode('utf-8')),
+ encoded_val))
except UnicodeEncodeError:
log.Log("Warning: unable to store Unicode extended attribute %s"
% repr(name), 3)
@@ -169,7 +175,8 @@ def Record2EA(record):
raise metadata.ParsingError("Bad record beginning: " + first[:8])
filename = first[8:]
if filename == '.': index = ()
- else: index = tuple(C.acl_unquote(filename).split('/'))
+ else: index = tuple(unicode(C.acl_unquote(filename.encode('utf-8')),
+ 'utf-8').split('/'))
ea = ExtendedAttributes(index)
for line in lines:
@@ -194,7 +201,7 @@ class EAExtractor(metadata.FlatExtractor):
def filename_to_index(self, filename):
"""Convert possibly quoted filename to index tuple"""
if filename == '.': return ()
- else: return tuple(C.acl_unquote(filename).split('/'))
+ else: return tuple(C.acl_unquote(filename.encode('utf-8')).split('/'))
class ExtendedAttributesFile(metadata.FlatFile):
"""Store/retrieve EAs from extended_attributes file"""
@@ -379,7 +386,7 @@ def set_rp_acl(rp, entry_list = None, default_entry_list = None,
else: acl = posix1e.ACL()
try:
- acl.applyto(rp.path)
+ acl.applyto(rp.path.encode('utf-8'))
except IOError, exc:
if exc[0] == errno.EOPNOTSUPP:
log.Log("Warning: unable to set ACL on %s: %s" %
@@ -391,12 +398,12 @@ def set_rp_acl(rp, entry_list = None, default_entry_list = None,
if default_entry_list:
def_acl = list_to_acl(default_entry_list, map_names)
else: def_acl = posix1e.ACL()
- def_acl.applyto(rp.path, posix1e.ACL_TYPE_DEFAULT)
+ def_acl.applyto(rp.path.encode('utf-8'), posix1e.ACL_TYPE_DEFAULT)
def get_acl_lists_from_rp(rp):
"""Returns (acl_list, def_acl_list) from an rpath. Call locally"""
assert rp.conn is Globals.local_connection
- try: acl = posix1e.ACL(file=rp.path)
+ try: acl = posix1e.ACL(file=rp.path.encode('utf-8'))
except IOError, exc:
if exc[0] == errno.EOPNOTSUPP:
acl = None
@@ -406,7 +413,7 @@ def get_acl_lists_from_rp(rp):
acl = None
else: raise
if rp.isdir():
- try: def_acl = posix1e.ACL(filedef=rp.path)
+ try: def_acl = posix1e.ACL(filedef=rp.path.encode('utf-8'))
except IOError, exc:
if exc[0] == errno.EOPNOTSUPP:
def_acl = None
@@ -533,7 +540,8 @@ def acl_compare_rps(rp1, rp2):
def ACL2Record(acl):
"""Convert an AccessControlLists object into a text record"""
- return '# file: %s\n%s\n' % (C.acl_quote(acl.get_indexpath()), str(acl))
+ return '# file: %s\n%s\n' % \
+ (C.acl_quote(acl.get_indexpath().encode('utf-8')), str(acl))
def Record2ACL(record):
"""Convert text record to an AccessControlLists object"""
@@ -543,7 +551,8 @@ def Record2ACL(record):
raise metadata.ParsingError("Bad record beginning: "+ first_line)
filename = first_line[8:]
if filename == '.': index = ()
- else: index = tuple(C.acl_unquote(filename).split('/'))
+ else: index = tuple(unicode(C.acl_unquote(filename.encode('utf-8')),
+ 'utf-8').split('/'))
return AccessControlLists(index, record[newline_pos:])
class ACLExtractor(EAExtractor):