From f5c1cf9992277761c06643b23e355fb5a35fe036 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 10 Jul 2020 11:07:32 +0200 Subject: [PATCH] bpo-38893: Ignore EACCES, ENOSYS in copyxattr :func:`shutil.copystat` now ignores :const:`errno.ENOSYS` and :const:`errno.EACCES` when copying extended file attributes. :func:`os.listxattr` can fail with ENOSYS on some file systems (e.g. NFS). An LSM may block :func:`os.setxattr` for security attributes like ``security.selinux``. Signed-off-by: Christian Heimes --- Lib/shutil.py | 7 ++++--- .../next/Library/2020-07-10-11-01-44.bpo-38893.HNE1L4.rst | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-07-10-11-01-44.bpo-38893.HNE1L4.rst diff --git a/Lib/shutil.py b/Lib/shutil.py index a4ce2c0290bc93..5ae0a20b112988 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -317,7 +317,8 @@ def _copyxattr(src, dst, *, follow_symlinks=True): try: names = os.listxattr(src, follow_symlinks=follow_symlinks) except OSError as e: - if e.errno not in (errno.ENOTSUP, errno.ENODATA, errno.EINVAL): + if e.errno not in (errno.ENOTSUP, errno.ENODATA, errno.EINVAL, + errno.ENOSYS): raise return for name in names: @@ -325,8 +326,8 @@ def _copyxattr(src, dst, *, follow_symlinks=True): value = os.getxattr(src, name, follow_symlinks=follow_symlinks) os.setxattr(dst, name, value, follow_symlinks=follow_symlinks) except OSError as e: - if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA, - errno.EINVAL): + if e.errno not in (errno.EPERM, errno.EACCES, errno.ENOTSUP, + errno.ENODATA, errno.EINVAL): raise else: def _copyxattr(*args, **kwargs): diff --git a/Misc/NEWS.d/next/Library/2020-07-10-11-01-44.bpo-38893.HNE1L4.rst b/Misc/NEWS.d/next/Library/2020-07-10-11-01-44.bpo-38893.HNE1L4.rst new file mode 100644 index 00000000000000..00b59bdabb144d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-10-11-01-44.bpo-38893.HNE1L4.rst @@ -0,0 +1,5 @@ +:func:`shutil.copystat` now ignores :const:`errno.ENOSYS` and +:const:`errno.EACCES` when copying extended file attributes. +:func:`os.listxattr` can fail with ENOSYS on some file systems (e.g. NFS). +An LSM may block :func:`os.setxattr` for security attributes like +``security.selinux``.