Skip to content

[2.7] bpo-34260, shutil: fix copy2 and copystat documentation (GH-8523) #10071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Doc/library/shutil.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ Directory and files operations

.. function:: copy2(src, dst)

Similar to :func:`shutil.copy`, but metadata is copied as well -- in fact,
this is just :func:`shutil.copy` followed by :func:`copystat`. This is
similar to the Unix command :program:`cp -p`.
Identical to :func:`~shutil.copy` except that :func:`copy2`
also attempts to preserve file metadata.

:func:`copy2` uses :func:`copystat` to copy the file metadata.
Please see :func:`copystat` for more information.


.. function:: ignore_patterns(\*patterns)
Expand Down
13 changes: 11 additions & 2 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def copymode(src, dst):
os.chmod(dst, mode)

def copystat(src, dst):
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst"""
"""Copy file metadata

Copy the permission bits, last access time, last modification time, and
flags from `src` to `dst`. On Linux, copystat() also copies the "extended
attributes" where possible. The file contents, owner, and group are
unaffected. `src` and `dst` are path names given as strings.
"""
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
if hasattr(os, 'utime'):
Expand Down Expand Up @@ -134,7 +140,10 @@ def copy(src, dst):
copymode(src, dst)

def copy2(src, dst):
"""Copy data and all stat info ("cp -p src dst").
"""Copy data and metadata. Return the file's destination.

Metadata is copied with copystat(). Please see the copystat function
for more information.

The destination may be a directory.

Expand Down