diff options
author | Olexa Bilaniuk <obilaniu@users.noreply.github.com> | 2019-05-10 03:22:06 (GMT) |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-05-10 03:22:06 (GMT) |
commit | 79efbb719383386051c72f2ee932eeca8e033e6b (patch) | |
tree | ca694616676aaad7de81f41ee5d1b16dd18455be /Lib/shutil.py | |
parent | 948ed8c96b6912541a608591efe3e00fb520429a (diff) | |
download | cpython-79efbb719383386051c72f2ee932eeca8e033e6b.zip cpython-79efbb719383386051c72f2ee932eeca8e033e6b.tar.gz cpython-79efbb719383386051c72f2ee932eeca8e033e6b.tar.bz2 |
bpo-24538: Fix bug in shutil involving the copying of xattrs to read-only files. (PR-13212)
Extended attributes can only be set on user-writeable files, but shutil previously
first chmod()ed the destination file to the source's permissions and then tried to
copy xattrs. This will cause failures if attempting to copy read-only files with
xattrs, as occurs with Git clones on Lustre FS.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 6cfe373..b2e8f5f 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. |