Repository navigation
Conversation
copytree() now accepts copy_dir_stat (default true). When false, directory permissions and times are not copied with copystat(), e.g. to copy a read-only tree into a writable one. The flag propagates through recursive calls; file metadata is unaffected and remains handled by copy_function. Document the parameter and cover both behaviors with tests. Co-authored-by: Muse Code (Meta Muse Spark)
Documentation build overview
28 files changed ·
|
WASI cannot change file mode bits, so skip the new copytree mode tests there like the other chmod-dependent tests in test_shutil. Co-authored-by: Muse Code (Meta Muse Spark)
itamaro
left a comment
There was a problem hiding this comment.
does this need a whatsnew bullet too?
| def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, | ||
| ignore_dangling_symlinks=False, dirs_exist_ok=False): | ||
| ignore_dangling_symlinks=False, dirs_exist_ok=False, | ||
| copy_dir_stat=True): |
There was a problem hiding this comment.
this is a long args list. maybe at make new ones kw-only?
| copy_dir_stat=True): | |
| *, copy_dir_stat=True): |
| If *copy_dir_stat* is false, permissions and times of directories are | ||
| not copied, e.g. to copy a read-only tree into a writable one. It | ||
| defaults to true. File metadata is always handled by *copy_function*. | ||
|
|
There was a problem hiding this comment.
perhaps need different phrasing or clarification that, by default, just setting this to False will not magically make a read-only tree writable -- you also need to use a custom copy function, e.g. copy_function=shutil.copyfile
| self.assertEqual(os.stat(restrictive_subdir).st_mode, | ||
| os.stat(restrictive_subdir_dst).st_mode) | ||
|
|
||
| @os_helper.skip_unless_working_chmod |
There was a problem hiding this comment.
nit: also assert on whether the times are copied or not (as per the documented behavior)
| Permissions and times of directories are copied with :func:`copystat`, | ||
| individual files are copied using :func:`~shutil.copy2`. | ||
|
|
||
| If *copy_dir_stat* is false, permissions and times of directories are |
There was a problem hiding this comment.
nit: "permissions and times" is a subset of the metadata that's copied (or not).
Supersedes #109717 (closed).
Adds a
copy_dir_statparameter (default true) toshutil.copytree(). When false, directory permissions and times are not copied withcopystat(), e.g. to copy a read-only tree into a writable one. Unlike the superseded PR, the flag propagates through recursive calls, and file metadata stays withcopy_function(documented). Includes tests, docs, and a news entry.