8000 Add switch parameter "copy_stat" to shutil.copytree() · python/cpython@cc39b19 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit cc39b19

Browse files
committed
Add switch parameter "copy_stat" to shutil.copytree()
1 parent 34ddcc3 commit cc39b19

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/shutil.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def _ignore_patterns(path, names):
477477
return _ignore_patterns
478478

479479
def _copytree(entries, src, dst, symlinks, ignore, copy_function,
480-
ignore_dangling_symlinks, dirs_exist_ok=False):
480+
ignore_dangling_symlinks, dirs_exist_ok=False, copy_stat=True):
481481
if ignore is not None:
482482
ignored_names = ignore(os.fspath(src), [x.name for x in entries])
483483
else:
@@ -533,7 +533,8 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
533533
except OSError as why:
534534
errors.append((srcname, dstname, str(why)))
535535
try:
536-
copystat(src, dst)
536+
if copy_stat == True :
537+
copystat(src, dst)
537538
except OSError as why:
538539
# Copying file access times may fail on Windows
539540
if getattr(why, 'winerror', None) is None:
@@ -543,7 +544,7 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
543544
return dst
544545

545546
def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
546-
ignore_dangling_symlinks=False, dirs_exist_ok=False):
547+
ignore_dangling_symlinks=False, dirs_exist_ok=False, copy_stat=True):
547548
"""Recursively copy a directory tree and return the destination directory.
548549
549550
If exception(s) occur, an Error is raised with a list of reasons.
@@ -588,7 +589,7 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
588589
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
589590
ignore=ignore, copy_function=copy_function,
590591
ignore_dangling_symlinks=ignore_dangling_symlinks,
591-
dirs_exist_ok=dirs_exist_ok)
592+
dirs_exist_ok=dirs_exist_ok, copy_stat=copy_stat)
592593

593594
if hasattr(os.stat_result, 'st_file_attributes'):
594595
def _rmtree_islink(path):

0 commit comments

Comments
 (0)
0