summaryrefslogtreecommitdiff
path: root/Lib/shutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 6cfe3738f6..b2e8f5fd75 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -359,6 +359,9 @@ def copystat(src, dst, *, follow_symlinks=True):
mode = stat.S_IMODE(st.st_mode)
lookup("utime")(dst, ns=(st.st_atime_ns, st.st_mtime_ns),
follow_symlinks=follow)
+ # We must copy extended attributes before the file is (potentially)
+ # chmod()'ed read-only, otherwise setxattr() will error with -EACCES.
+ _copyxattr(src, dst, follow_symlinks=follow)
try:
lookup("chmod")(dst, mode, follow_symlinks=follow)
except NotImplementedError:
@@ -382,7 +385,6 @@ def copystat(src, dst, *, follow_symlinks=True):
break
else:
raise
- _copyxattr(src, dst, follow_symlinks=follow)
def copy(src, dst, *, follow_symlinks=True):
"""Copy data and mode bits ("cp src dst"). Return the file's destination.