]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/metadata.py
Use *native* type sizes in file attr guard
[bup.git] / lib / bup / metadata.py
index 05b47bd7b1b8f4c70394ab1eeee7c2c5c10c4cdc..390c5acd0b3fea214d8ffa5e55374440ebff679e 100644 (file)
@@ -4,7 +4,7 @@
 #
 # 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
@@ -42,7 +42,20 @@ except ImportError:
     # 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!
 
@@ -434,7 +447,7 @@ class Metadata:
             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
@@ -554,6 +567,7 @@ class Metadata:
     ## 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:
@@ -585,6 +599,7 @@ class Metadata:
 
     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)
@@ -645,7 +660,7 @@ class Metadata:
             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:
@@ -656,7 +671,7 @@ class Metadata:
                 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])
@@ -665,7 +680,7 @@ class Metadata:
                 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
 
@@ -914,7 +929,7 @@ def summary_str(meta, numeric_ids = False, classification = None,
             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: