def copystats(from_file, to_file):
"""
Copy stat info from ``from_file`` to ``to_file`` using `shutil.copystat`.
If possible, also copy the user and/or group ownership information.
"""
shutil.copystat(from_file, to_file)
if hasattr(os, 'chown'):
st = os.stat(from_file)
# Based on GNU sed's behavior:
try:
os.chown(to_file, st.st_uid, st.st_gid)
except EnvironmentError:
try:
os.chown(to_file, -1, st.st_gid)
except EnvironmentError:
pass
评论列表
文章目录