#
# This code is covered under the terms of the GNU Library General
# Public License as described in the bup LICENSE file.
-import errno, os, sys, stat, time, pwd, grp, socket
+import errno, os, sys, stat, time, pwd, grp, socket, struct
from cStringIO import StringIO
from bup import vint, xstat
from bup.drecurse import recursive_dirlist
# not on Linux, in which case files don't have any linux attrs anyway, so
# lacking the functions isn't a problem.
get_linux_file_attr = set_linux_file_attr = None
-
+
+
+# See the bup_get_linux_file_attr() comments.
+_suppress_linux_file_attr = \
+ sys.byteorder == 'big' and struct.calcsize('@l') > struct.calcsize('@i')
+
+def check_linux_file_attr_api():
+ global get_linux_file_attr, set_linux_file_attr
+ if not (get_linux_file_attr or set_linux_file_attr):
+ return
+ if _suppress_linux_file_attr:
+ log('Warning: Linux attr support disabled (see "bup help index").\n')
+ get_linux_file_attr = set_linux_file_attr = None
+
# WARNING: the metadata encoding is *not* stable yet. Caveat emptor!
if stat.S_ISLNK(st.st_mode):
self.symlink_target = os.readlink(path)
except OSError, e:
- add_error('readlink: %s', e)
+ add_error('readlink: %s' % e)
def _encode_symlink_target(self):
return self.symlink_target
## Linux attributes (lsattr(1), chattr(1))
def _add_linux_attr(self, path, st):
+ check_linux_file_attr_api()
if not get_linux_file_attr: return
if stat.S_ISREG(st.st_mode) or stat.S_ISDIR(st.st_mode):
try:
def _apply_linux_attr_rec(self, path, restore_numeric_ids=False):
if self.linux_attr:
+ check_linux_file_attr_api()
if not set_linux_file_attr:
add_error("%s: can't restore linuxattrs: "
"linuxattr support missing.\n" % path)
existing_xattrs = set(xattr.list(path, nofollow=True))
except IOError, e:
if e.errno == errno.EACCES:
- raise ApplyError('xattr.set: %s' % e)
+ raise ApplyError('xattr.set %r: %s' % (path, e))
else:
raise
for k, v in self.linux_xattr:
except IOError, e:
if e.errno == errno.EPERM \
or e.errno == errno.EOPNOTSUPP:
- raise ApplyError('xattr.set: %s' % e)
+ raise ApplyError('xattr.set %r: %s' % (path, e))
else:
raise
existing_xattrs -= frozenset([k])
xattr.remove(path, k, nofollow=True)
except IOError, e:
if e.errno == errno.EPERM:
- raise ApplyError('xattr.remove: %s' % e)
+ raise ApplyError('xattr.remove %r: %s' % (path, e))
else:
raise
if meta.rdev:
size_or_dev_str = '%d,%d' % (os.major(meta.rdev),
os.minor(meta.rdev))
- elif meta.size:
+ elif meta.size != None:
if human_readable:
size_or_dev_str = format_filesize(meta.size)
else: