diff options
author | Hynek Schlawack <hs@ox.cx> | 2013-02-05 08:25:24 +0100 |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2013-02-05 08:25:24 +0100 |
commit | 4cd7b9c3e942b8afdbd41df16837fc09b5fb8993 (patch) | |
tree | 96425a840b98cbd0ff1fa76378bafdabfae438f1 | |
parent | 1f0044c473e8fb10b3f7ec7624b08a9ee44e642f (diff) | |
parent | 0beab058dd431a7c0d62cfc50d8503616e01fd17 (diff) | |
download | cpython-git-4cd7b9c3e942b8afdbd41df16837fc09b5fb8993.tar.gz |
#17076: Make copying of xattrs more permissive of missing FS support
Patch by Thomas Wouters.
-rw-r--r-- | Lib/shutil.py | 8 | ||||
-rw-r--r-- | Lib/test/test_shutil.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 21 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 0cc74f6b97..c2f0278bc9 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -140,7 +140,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 07d0ec9bd8..5a78440580 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -450,6 +450,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') @@ -235,6 +235,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. |