]> granicus.if.org Git - python/commitdiff
#17076: Make copying of xattrs more permissive of missing FS support
authorHynek Schlawack <hs@ox.cx>
Tue, 5 Feb 2013 07:22:44 +0000 (08:22 +0100)
committerHynek Schlawack <hs@ox.cx>
Tue, 5 Feb 2013 07:22:44 +0000 (08:22 +0100)
Patch by Thomas Wouters.

Lib/shutil.py
Lib/test/test_shutil.py
Misc/NEWS

index e4b640cd17f32a2f1bfece5fdf7a19548af449a0..a1884083087073512c1f8f63278798e755cb567e 100644 (file)
@@ -142,7 +142,13 @@ if hasattr(os, 'listxattr'):
 
         """
 
-        for name in os.listxattr(src, follow_symlinks=follow_symlinks):
+        try:
+            names = os.listxattr(src, follow_symlinks=follow_symlinks)
+        except OSError as e:
+            if e.errno not in (errno.ENOTSUP, errno.ENODATA):
+                raise
+            return
+        for name in names:
             try:
                 value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
                 os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
index 8ac350a943b5fd59d248d085861882fe1e30ea0c..3b1b6949d066fc5a83393f5b86f358fceabeb49e 100644 (file)
@@ -449,6 +449,17 @@ class TestShutil(unittest.TestCase):
             self.assertIn('user.bar', os.listxattr(dst))
         finally:
             os.setxattr = orig_setxattr
+        # the source filesystem not supporting xattrs should be ok, too.
+        def _raise_on_src(fname, *, follow_symlinks=True):
+            if fname == src:
+                raise OSError(errno.ENOTSUP, 'Operation not supported')
+            return orig_listxattr(fname, follow_symlinks=follow_symlinks)
+        try:
+            orig_listxattr = os.listxattr
+            os.listxattr = _raise_on_src
+            shutil._copyxattr(src, dst)
+        finally:
+            os.listxattr = orig_listxattr
 
         # test that shutil.copystat copies xattrs
         src = os.path.join(tmp_dir, 'the_original')
index ce24d0e4ab5f86edc9ba05d2a6b322662f0daab4..122b228ff69022523617d0cd5c65c557354e8a19 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -163,6 +163,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #17076: Make copying of xattrs more permissive of missing FS support.
+  Patch by Thomas Wouters.
+
 - Issue #17089: Expat parser now correctly works with string input not only when
   an internal XML encoding is UTF-8 or US-ASCII.  It now accepts bytes and
   strings larger than 2 GiB.