changeset: 82013:47c65639390d branch: 3.3 parent: 82010:e64b74227198 user: Hynek Schlawack date: Tue Feb 05 08:22:44 2013 +0100 files: Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS description: #17076: Make copying of xattrs more permissive of missing FS support Patch by Thomas Wouters. diff -r e64b74227198 -r 47c65639390d Lib/shutil.py --- a/Lib/shutil.py Mon Feb 04 15:22:53 2013 -0500 +++ b/Lib/shutil.py Tue Feb 05 08:22:44 2013 +0100 @@ -142,7 +142,13 @@ """ - 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 -r e64b74227198 -r 47c65639390d Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Mon Feb 04 15:22:53 2013 -0500 +++ b/Lib/test/test_shutil.py Tue Feb 05 08:22:44 2013 +0100 @@ -449,6 +449,17 @@ 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') diff -r e64b74227198 -r 47c65639390d Misc/NEWS --- a/Misc/NEWS Mon Feb 04 15:22:53 2013 -0500 +++ b/Misc/NEWS Tue Feb 05 08:22:44 2013 +0100 @@ -163,6 +163,9 @@ 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.