diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/shutil.py | 8 | ||||
-rw-r--r-- | Lib/test/test_shutil.py | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index e4b640c..a188408 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -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) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 8ac350a..3b1b694 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -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') |