Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 797cfbd

Browse files
csernazsvstinner
authored andcommitted
[3.6] bpo-34260, shutil: fix copy2 and copystat documentation (GH-8523) (GH-10068)
Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring. (cherry picked from commit 4f399be)
1 parent 2c54925 commit 797cfbd

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Directory and files operations
166166
.. function:: copy2(src, dst, *, follow_symlinks=True)
167167

168168
Identical to :func:`~shutil.copy` except that :func:`copy2`
169-
also attempts to preserve all file metadata.
169+
also attempts to preserve file metadata.
170170

171171
When *follow_symlinks* is false, and *src* is a symbolic
172172
link, :func:`copy2` attempts to copy all metadata from the

Lib/shutil.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ def _copyxattr(*args, **kwargs):
171171
pass
172172

173173
def copystat(src, dst, *, follow_symlinks=True):
174-
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
174+
"""Copy file metadata
175175
176-
If the optional flag `follow_symlinks` is not set, symlinks aren't followed if and
177-
only if both `src` and `dst` are symlinks.
176+
Copy the permission bits, last access time, last modification time, and
177+
flags from `src` to `dst`. On Linux, copystat() also copies the "extended
178+
attributes" where possible. The file contents, owner, and group are
179+
unaffected. `src` and `dst` are path names given as strings.
178180
181+
If the optional flag `follow_symlinks` is not set, symlinks aren't
182+
followed if and only if both `src` and `dst` are symlinks.
179183
"""
180184
def _nop(*args, ns=None, follow_symlinks=None):
181185
pass
@@ -243,8 +247,10 @@ def copy(src, dst, *, follow_symlinks=True):
243247
return dst
244248

245249
def copy2(src, dst, *, follow_symlinks=True):
246-
"""Copy data and all stat info ("cp -p src dst"). Return the file's
247-
destination."
250+
"""Copy data and metadata. Return the file's destination.
251+
252+
Metadata is copied with copystat(). Please see the copystat function
253+
for more information.
248254
249255
The destination may be a directory.
250256

0 commit comments

Comments
 (0)