Skip to content

Commit 4f399be

Browse files
csernazsvstinner
authored andcommitted
bpo-34260, shutil: fix copy2 and copystat documentation (GH-8523)
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.
1 parent b79b5c0 commit 4f399be

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Doc/library/shutil.rst

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

179179
Identical to :func:`~shutil.copy` except that :func:`copy2`
180-
also attempts to preserve all file metadata.
180+
also attempts to preserve file metadata.
181181

182182
When *follow_symlinks* is false, and *src* is a symbolic
183183
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
@@ -312,11 +312,15 @@ def _copyxattr(*args, **kwargs):
312312
pass
313313

314314
def copystat(src, dst, *, follow_symlinks=True):
315-
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
315+
"""Copy file metadata
316316
317-
If the optional flag `follow_symlinks` is not set, symlinks aren't followed if and
318-
only if both `src` and `dst` are symlinks.
317+
Copy the permission bits, last access time, last modification time, and
318+
flags from `src` to `dst`. On Linux, copystat() also copies the "extended
319+
attributes" where possible. The file contents, owner, and group are
320+
unaffected. `src` and `dst` are path names given as strings.
319321
322+
If the optional flag `follow_symlinks` is not set, symlinks aren't
323+
followed if and only if both `src` and `dst` are symlinks.
320324
"""
321325
def _nop(*args, ns=None, follow_symlinks=None):
322326
pass
@@ -384,8 +388,10 @@ def copy(src, dst, *, follow_symlinks=True):
384388
return dst
385389

386390
def copy2(src, dst, *, follow_symlinks=True):
387-
"""Copy data and all stat info ("cp -p src dst"). Return the file's
388-
destination.
391+
"""Copy data and metadata. Return the file's destination.
392+
393+
Metadata is copied with copystat(). Please see the copystat function
394+
for more information.
389395
390396
The destination may be a directory.
391397

0 commit comments

Comments
 (0)