mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
#17076: Make copying of xattrs more permissive of missing FS support
Patch by Thomas Wouters.
This commit is contained in:
commit
4cd7b9c3e9
3 changed files with 21 additions and 1 deletions
|
@ -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:
|
try:
|
||||||
value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
|
value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
|
||||||
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
|
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
|
||||||
|
|
|
@ -450,6 +450,17 @@ class TestShutil(unittest.TestCase):
|
||||||
self.assertIn('user.bar', os.listxattr(dst))
|
self.assertIn('user.bar', os.listxattr(dst))
|
||||||
finally:
|
finally:
|
||||||
os.setxattr = orig_setxattr
|
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
|
# test that shutil.copystat copies xattrs
|
||||||
src = os.path.join(tmp_dir, 'the_original')
|
src = os.path.join(tmp_dir, 'the_original')
|
||||||
|
|
|
@ -235,6 +235,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- 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
|
an internal XML encoding is UTF-8 or US-ASCII. It now accepts bytes and
|
||||||
strings larger than 2 GiB.
|
strings larger than 2 GiB.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue