mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
948ed8c96b
commit
79efbb7193
4 changed files with 15 additions and 1 deletions
|
@ -531,12 +531,20 @@ class TestShutil(unittest.TestCase):
|
|||
|
||||
# test that shutil.copystat copies xattrs
|
||||
src = os.path.join(tmp_dir, 'the_original')
|
||||
srcro = os.path.join(tmp_dir, 'the_original_ro')
|
||||
write_file(src, src)
|
||||
write_file(srcro, srcro)
|
||||
os.setxattr(src, 'user.the_value', b'fiddly')
|
||||
os.setxattr(srcro, 'user.the_value', b'fiddly')
|
||||
os.chmod(srcro, 0o444)
|
||||
dst = os.path.join(tmp_dir, 'the_copy')
|
||||
dstro = os.path.join(tmp_dir, 'the_copy_ro')
|
||||
write_file(dst, dst)
|
||||
write_file(dstro, dstro)
|
||||
shutil.copystat(src, dst)
|
||||
shutil.copystat(srcro, dstro)
|
||||
self.assertEqual(os.getxattr(dst, 'user.the_value'), b'fiddly')
|
||||
self.assertEqual(os.getxattr(dstro, 'user.the_value'), b'fiddly')
|
||||
|
||||
@support.skip_unless_symlink
|
||||
@support.skip_unless_xattr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue