]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/metadata.py
Ignore lchmod() ENOSYS (i.e. function not implemented)
[bup.git] / lib / bup / metadata.py
index b4cedf32005cd9960d7110a7537692a9c2980e68..bef806677220a899b7d5328fc44a2555f9d51767 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!
 
@@ -410,7 +423,10 @@ class Metadata:
                     raise
 
         if _have_lchmod:
-            os.lchmod(path, stat.S_IMODE(self.mode))
+            try:
+                os.lchmod(path, stat.S_IMODE(self.mode))
+            except errno.ENOSYS:  # Function not implemented
+                pass
         elif not stat.S_ISLNK(self.mode):
             os.chmod(path, stat.S_IMODE(self.mode))
 
@@ -434,7 +450,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 +570,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 +602,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)